first commit

This commit is contained in:
ryanwong
2022-04-12 08:57:07 -04:00
commit 1bab399b38
446 changed files with 109788 additions and 0 deletions
@@ -0,0 +1,64 @@
'use strict';
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
/**
* @copyright 2021 Manaknightdigital Inc.
* @link https://manaknightdigital.com
* @license Proprietary Software licensing
* @author Ryan Wong
*/
const archiver = require('archiver');
const AWS = require('aws-sdk');
const s3 = new AWS.S3();
const stream = require('stream');
const path = require('path');
AWS.config.update({
accessKeyId: process.env.DYNAMIC_CONFIG_AWS_KEY,
secretAccessKey: process.env.DYNAMIC_CONFIG_AWS_SECRET,
region: process.env.DYNAMIC_CONFIG_AWS_REGION,
});
const main = async () => {
const archive = archiver('zip', {
zlib: { level: 9 }, // Sets the compression level.
});
archive.directory(path.join(__dirname, '../../', '/uploads'), false);
const uploadStream = new stream.PassThrough();
archive.pipe(uploadStream);
archive.finalize();
archive.on('warning', function (err) {
if (err.code === 'ENOENT') {
console.log(err);
} else {
throw err;
}
});
archive.on('error', function (err) {
throw err;
});
archive.on('end', function () {
console.log('archive end');
});
await uploadFromStream(uploadStream);
console.log('all done');
};
const uploadFromStream = async (pass) => {
const s3params = {
Bucket: process.env.DYNAMIC_CONFIG_AWS_BUCKET,
Key: `uploads.zip`,
Body: pass,
ContentType: 'application/zip',
};
return s3.upload(s3params).promise();
};
main();
@@ -0,0 +1,42 @@
'use strict';
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
/**
* @copyright 2021 Manaknightdigital Inc.
* @link https://manaknightdigital.com
* @license Proprietary Software licensing
* @author Ryan Wong
*/
const AWS = require('aws-sdk');
const S3 = new AWS.S3();
const db = require('../models');
AWS.config.update({
accessKeyId: process.env.DYNAMIC_CONFIG_AWS_KEY,
secretAccessKey: process.env.DYNAMIC_CONFIG_AWS_SECRET,
region: process.env.DYNAMIC_CONFIG_AWS_REGION,
});
async function main() {
/** @type {Array.<{url: string}>} */
const images = await db.image.getAllByStatus(0);
const mapKeys = images.map(({ url }) => {
// TODO: DO MAPPING
return url;
});
const params = {
Bucket: process.env.AWS_S3_BUCKET,
Delete: { Objects: mapKeys },
};
S3.deleteObjects(params, (error, data) => {
if (error) console.log(error);
else console.log(data);
});
}
main();
@@ -0,0 +1,16 @@
'use strict';
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
/**
* @copyright 2021 Manaknightdigital Inc.
* @link https://manaknightdigital.com
* @license Proprietary Software licensing
* @author Ryan Wong
*/
const db = require('../models');
(async function tokenCronJob() {
await db.query('UPDATE `token` SET status=0 WHERE `expire_at` < NOW();');
await db.query('DELETE FROM `token` WHERE status=0;');
})();