forked from omaralsakka/Hypertube
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnext.config.mjs
77 lines (68 loc) · 2.04 KB
/
next.config.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// @ts-check
import { env } from "./src/env/server.mjs";
import { PrismaClient } from "@prisma/client";
import { CronJob } from 'cron';
import fs from 'fs';
/**
* Don't be scared of the generics here.
* All they do is to give us autocompletion when using this.
*
* @template {import('next').NextConfig} T
* @param {T} config - A generic parameter that flows through to the return type
* @constraint {{import('next').NextConfig}}
*/
function defineNextConfig(config) {
return config;
}
const job = new CronJob(
'0 23 * * *',
async function () {
console.log('You will see this message every second');
const prisma =
global.prisma ||
new PrismaClient({
log:
env.NODE_ENV === "development" ? ["query", "error", "warn"] : ["error"],
});
let downloadedMovies = [];
let timestamp = Date.now();
try {
downloadedMovies = await prisma?.movies.findMany();
} catch (error) {
console.error(error);
}
let moviesToDelete = [];
downloadedMovies?.filter((movie) => {
if(Date.parse(movie.date) < timestamp - 2629800000) { // can use 1 instead of 2629800000 (1 month) to test. these are milliseconds
moviesToDelete.push(movie);
}
})
moviesToDelete.map(async (movie) => {
if (fs.existsSync(`./movies/${movie.imdb_code}`)) { // make sure this works properly
fs.rmSync(`./movies/${movie.imdb_code}`, { recursive: true, force: true });
}
await prisma?.movies.delete({
where: {
imdb_code: movie.imdb_code
}
})
})
},
null,
true,
'Europe/Helsinki'
);
export default defineNextConfig({
reactStrictMode: true,
swcMinify: true,
/** Next.js i18n docs:
* @see https://nextjs.org/docs/advanced-features/i18n-routing
* Reference repo for i18n:
* @see https://github.com/juliusmarminge/t3-i18n
**/
i18n: {
locales: ["en"],
defaultLocale: "en",
},
output: "standalone",
});