Browse Source

feat(export): enhance export functionality with new download method and configuration updates

- Introduced a new function to open export downloads in a new tab, improving user experience for task downloads.
- Updated the export job service to use more precise checks for task expiration, enhancing reliability.
- Modified the .gitignore to include temporary files, ensuring a cleaner project structure.

These changes streamline the export process and improve the management of temporary files.
main
npmrun 2 weeks ago
parent
commit
941b082a72
  1. 3
      .gitignore
  2. 8
      app/pages/me/export/index.vue
  3. BIN
      packages/drizzle-pkg/db.sqlite
  4. 13
      server/service/export/jobs.ts

3
.gitignore

@ -29,4 +29,5 @@ logs
# Local git worktrees # Local git worktrees
.worktrees .worktrees
static/* static/*
.tmp/*

8
app/pages/me/export/index.vue

@ -58,6 +58,10 @@ function taskDownloadUrl(taskId: number): string {
return `/api/me/export/tasks/${taskId}/download` return `/api/me/export/tasks/${taskId}/download`
} }
function openExportDownload(taskId: number) {
window.open(taskDownloadUrl(taskId), '_blank', 'noopener,noreferrer')
}
async function loadTasks() { async function loadTasks() {
const useBlocking = tasks.value.length === 0 const useBlocking = tasks.value.length === 0
if (useBlocking) { if (useBlocking) {
@ -215,10 +219,8 @@ onMounted(() => {
<UButton <UButton
v-if="task.status === 'succeeded'" v-if="task.status === 'succeeded'"
icon="i-lucide-download" icon="i-lucide-download"
:to="taskDownloadUrl(task.id)"
target="_blank"
rel="noopener"
size="sm" size="sm"
@click="openExportDownload(task.id)"
> >
下载 下载
</UButton> </UButton>

BIN
packages/drizzle-pkg/db.sqlite

Binary file not shown.

13
server/service/export/jobs.ts

@ -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 > 0n ? 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", 2n * 1024n * 1024n * 1024n); 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";

Loading…
Cancel
Save