Skip to content

Commit

Permalink
feat: make download link valid for 24 hours
Browse files Browse the repository at this point in the history
  • Loading branch information
aalemayhu committed Sep 29, 2024
1 parent d5fb05b commit bec718e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
14 changes: 11 additions & 3 deletions src/lib/storage/jobs/ScheduleCleanup.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { Knex } from 'knex';

import { MS_21 } from './helpers/deleteOldUploads';
import { runCleanup } from './helpers/runCleanup';
import deleteOldUploads, {
MS_21,
MS_24_HOURS,
} from './helpers/deleteOldUploads';
import { runFileSystemCleanup } from './helpers/runFileSystemCleanup';

export const ScheduleCleanup = (db: Knex) => {
setInterval(() => runCleanup(db), MS_21);
setInterval(() => runFileSystemCleanup(db), MS_21);

setInterval(
() => deleteOldUploads(db).then(() => console.info('deleted old uploads')),
MS_24_HOURS
);
};
2 changes: 2 additions & 0 deletions src/lib/storage/jobs/helpers/deleteOldUploads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { TIME_21_MINUTES_AS_SECONDS } from '../../../constants';
import StorageHandler from '../../StorageHandler';

export const MS_21 = TIME_21_MINUTES_AS_SECONDS * 1000;
export const MS_24_HOURS = 1000 * 60 * 60 * 24;

const MAX_KEYS = 100_000;

const deleteNonSubScriberUploads = async (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@ import os from 'os';
import { Knex } from 'knex';

import deleteOldFiles from './deleteOldFiles';
import deleteOldUploads from './deleteOldUploads';
import { getDatabase } from '../../../../data_layer';

export const runCleanup = async (database: Knex) => {
export const runFileSystemCleanup = async (database: Knex) => {

Check failure on line 9 in src/lib/storage/jobs/helpers/runFileSystemCleanup.ts

View workflow job for this annotation

GitHub Actions / build (18.16.1)

Async arrow function has no 'await' expression
console.time('running cleanup');
const locations = [
process.env.WORKSPACE_BASE ?? path.join(os.tmpdir(), 'workspaces'),
process.env.UPLOAD_BASE ?? path.join(os.tmpdir(), 'uploads'),
];

deleteOldFiles(locations);
await deleteOldUploads(database);
database.raw(
"DELETE FROM jobs WHERE created_at < NOW() - INTERVAL '14 days' AND status = 'failed'"
);
console.timeEnd('running cleanup');
};

if (require.main === module) {
runCleanup(getDatabase()).then(() => console.log('Cleanup complete'));
runFileSystemCleanup(getDatabase()).then(() => console.log('Cleanup complete'));

Check failure on line 24 in src/lib/storage/jobs/helpers/runFileSystemCleanup.ts

View workflow job for this annotation

GitHub Actions / build (18.16.1)

Replace `·console.log('Cleanup·complete')` with `⏎····console.log('Cleanup·complete')⏎··`
}
2 changes: 1 addition & 1 deletion src/services/EmailService/templates/convert-link.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div class="container">
<h1 class="title">Your converted deck is ready!</h1>
<p class="subtitle">
Download your converted deck here.
Download your converted deck here. This link is valid for 24 hours.

<a href="{{link}}">{{link}}</a>

Expand Down

0 comments on commit bec718e

Please sign in to comment.