Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function generateDownloadLinks(ctx, userID) {
const {
connectors: {
url: { BASE_URL },
secrets,
},
} = ctx;
// Generate a token for the download link.
const token = await secrets.jwt.sign(
{ user: userID },
{ jwtid: uuid.v4(), expiresIn: '1d', subject: DOWNLOAD_LINK_SUBJECT }
);
// Generate the url that a user can land on.
const downloadLandingURL = new URL('account/download', BASE_URL);
downloadLandingURL.hash = token;
// Generate the url that the API calls to download the actual zip.
const downloadFileURL = new URL('api/v1/account/download', BASE_URL);
downloadFileURL.searchParams.set('token', token);
return {
downloadLandingURL: downloadLandingURL.href,
downloadFileURL: downloadFileURL.href,
};
}
constructor(ctx) {
// Generate a new context id for the request if the parent doesn't provide
// one.
this.id = ctx.id || uuid.v4();
// Attach a logger or create one.
this.log = ctx.log || createLogger('graph:context', this.id);
// Load the current logged in user to `user`, otherwise this will be null.
this.user = get(ctx, 'user');
// Attach the connectors.
this.connectors = connectors;
// Create the loaders.
this.loaders = createLazyContextLoader(this, loaders);
// Create the mutators.
this.mutators = createLazyContextLoader(this, mutators);
socket.on('nextSong_response', (songdata) => {
if (FETCHING) {
FETCHING = false;
if (djtimer) {
clearTimeout(djtimer);
}
djtimer = undefined;
let dj = directory.getuser(socket.id);
if (songdata) {
let newguy = songdata;
newguy.PlaybackID = uuid.v4();
newguy.DJ = dj;
let now = new Date().getTime();
currentVideo = { Info: newguy, StartTime: now, EndTime: now + newguy.Duration };
socketManager.emit('song_start', { currVid: currentVideo });
} else {
remove_from_queue(dj.Username, (err) => {
playNextSong(() => {
console.log('DJ did not have a valid song. Skipping....');
});
});
}
}
});