Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live release 16 dec 2024 #721

Merged
merged 4 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
yarnPath: .yarn/releases/yarn-3.2.3.cjs
enableGlobalCache: true
nodeLinker: node-modules
checksumBehavior: update
1 change: 1 addition & 0 deletions src/dl.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ app.get('/level/:id', async (req, res, next) => {
res.set({
'Content-disposition': `attachment; filename=${filename}`,
'Content-Type': 'application/octet-stream',
'Access-Control-Expose-Headers': 'Content-Disposition',
});
readStream.pipe(res);
} catch (e) {
Expand Down
54 changes: 52 additions & 2 deletions src/utils/timefile.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { TimeFile, Time, SiteSetting } from '#data/models';
import { TimeFile, MultiTimeFile, Time, SiteSetting } from '#data/models';
import AWS from 'aws-sdk';
import fs from 'fs';
import util from 'util';
import { Op } from 'sequelize';
import { differenceInYears } from 'date-fns';
import { zipFiles } from '#utils/download';
import { dbquery } from '#data/sequelize';
import { uploadTimeFile } from '#utils/upload';
import { uuid } from '#utils/calcs';
import config from '../config.js';
import { checksumFile, s3Params, putObject } from '#utils/upload';

const deleteFile = util.promisify(fs.unlink);

const DO_endpoint = new AWS.Endpoint('ams3.digitaloceanspaces.com');
const DO_s3 = new AWS.S3({
Expand Down Expand Up @@ -190,6 +194,52 @@ export const coldStorage = async () => {
return { first, last };
};

const uploadTimeFile = async (
fileData,
TimeIndex = 0,
BattleIndex = 0,
Multi = 0,
) => {
const UUID = uuid();
let { timeFolder } = config;
let s3TimeFolder = 'time';
if (parseInt(Multi, 10) === 1) {
timeFolder = `multi-${timeFolder}`;
s3TimeFolder = 'multitime';
}
let filePath = `../events/${timeFolder}/${TimeIndex}.rec`;
let MD5 = null;
try {
MD5 = await checksumFile('md5', filePath);
const params = s3Params(
`${config.s3SubFolder}${s3TimeFolder}/${UUID}-${MD5}/${TimeIndex}.rec`,
fileData,
);
await putObject(params);
if (parseInt(Multi, 10) === 1) {
await MultiTimeFile.upsert({
MultiTimeIndex: TimeIndex,
BattleIndex,
UUID,
MD5,
});
} else {
await TimeFile.upsert({
TimeIndex,
BattleIndex,
UUID,
MD5,
});
}
await deleteFile(filePath);
} catch (e) {
// eslint-disable-next-line no-console
console.log('error', TimeIndex);
// eslint-disable-next-line no-console
console.log(e);
}
};

const uploadTimeFileIterator = async (fileName, multi = 0) => {
const TimeIndex = fileName.split('.')[0];
const getTime = await Time.findOne({ where: { TimeIndex }, raw: true });
Expand Down
2 changes: 1 addition & 1 deletion src/utils/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ export function uploadCupReplay(
});
}

const putObject = params => {
export const putObject = params => {
return new Promise((resolve, reject) => {
s3.putObject(params, err => {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2308,7 +2308,7 @@ __metadata:
"elma-js@https://github.com/ville-j/elma-js":
version: 1.0.0
resolution: "elma-js@https://github.com/ville-j/elma-js.git#commit=b93955b2de32f2896011e14d76e02ff1536348dc"
checksum: b5386e64c8dcb9780a1c6b60cd1ad34fe47eff44116bce046b1dbfa2545bcd5e8024c4fcc16723871063956f8edcb31de9558fd430b9fe1623d80faba5013911
checksum: 681fc8a3ad3675d3088475e112cc400237074ca34b18f2bfa26396fbb9eccb7082b6a964e30f580b4a45c936028fb8f233776c452760cd74892de9a0329281a4
languageName: node
linkType: hard

Expand Down
Loading