@ -2,7 +2,7 @@ import fs from "node:fs/promises";
import path from "node:path" ;
import path from "node:path" ;
import { dbGlobal } from "drizzle-pkg/lib/db" ;
import { dbGlobal } from "drizzle-pkg/lib/db" ;
import { userExportTasks } from "drizzle-pkg/lib/schema/export" ;
import { userExportTasks } from "drizzle-pkg/lib/schema/export" ;
import { and , desc , eq , or , sql } from "drizzle-orm" ;
import { and , desc , eq , gt , isNotNull , or , sql } from "drizzle-orm" ;
import { nextIntegerId } from "../../utils/sqlite-id" ;
import { nextIntegerId } from "../../utils/sqlite-id" ;
import { RELATIVE_TMP_DIR } from "#server/constants/media" ;
import { RELATIVE_TMP_DIR } from "#server/constants/media" ;
@ -24,7 +24,7 @@ function positiveBigIntFromEnv(name: string, fallback: bigint): bigint {
}
}
try {
try {
const n = BigInt ( raw ) ;
const n = BigInt ( raw ) ;
return n > 0 n ? n : fallback ;
return n > BigInt ( 0 ) ? n : fallback ;
} catch {
} catch {
return fallback ;
return fallback ;
}
}
@ -32,7 +32,10 @@ function positiveBigIntFromEnv(name: string, fallback: bigint): bigint {
const EXPORT_MAX_RUNNING_TASKS = positiveIntFromEnv ( "EXPORT_MAX_RUNNING_TASKS" , 2 ) ;
const EXPORT_MAX_RUNNING_TASKS = positiveIntFromEnv ( "EXPORT_MAX_RUNNING_TASKS" , 2 ) ;
const EXPORT_MAX_QUEUED_TASKS = positiveIntFromEnv ( "EXPORT_MAX_QUEUED_TASKS" , 30 ) ;
const EXPORT_MAX_QUEUED_TASKS = positiveIntFromEnv ( "EXPORT_MAX_QUEUED_TASKS" , 30 ) ;
const EXPORT_MAX_RETAINED_BYTES = positiveBigIntFromEnv ( "EXPORT_MAX_RETAINED_BYTES" , 2 n * 1024 n * 1024 n * 1024 n ) ;
const EXPORT_MAX_RETAINED_BYTES = positiveBigIntFromEnv (
"EXPORT_MAX_RETAINED_BYTES" ,
BigInt ( 2 ) * BigInt ( 1024 ) * BigInt ( 1024 ) * BigInt ( 1024 ) ,
) ;
function exportRootDir ( ) : string {
function exportRootDir ( ) : string {
return path . resolve ( process . cwd ( ) , RELATIVE_TMP_DIR , "exports" ) ;
return path . resolve ( process . cwd ( ) , RELATIVE_TMP_DIR , "exports" ) ;
@ -121,8 +124,8 @@ export async function createExportTask(params: { userId: number; maskPolicy: Exp
. where (
. where (
and (
and (
eq ( userExportTasks . status , "succeeded" ) ,
eq ( userExportTasks . status , "succeeded" ) ,
sql ` ${ userExportTasks . expiresAt } IS NOT NULL ` ,
isNotNull ( userExportTasks . expiresAt ) ,
sql ` ${ userExportTasks . expiresAt } > ${ now } ` ,
gt ( userExportTasks . expiresAt , now ) ,
) ,
) ,
) ;
) ;
const retainedBytes = retainedRows [ 0 ] ? . retainedBytes ? ? "0" ;
const retainedBytes = retainedRows [ 0 ] ? . retainedBytes ? ? "0" ;