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. 1
      .gitignore
  2. 8
      app/pages/me/export/index.vue
  3. BIN
      packages/drizzle-pkg/db.sqlite
  4. 13
      server/service/export/jobs.ts

1
.gitignore

@ -30,3 +30,4 @@ logs
.worktrees
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`
}
function openExportDownload(taskId: number) {
window.open(taskDownloadUrl(taskId), '_blank', 'noopener,noreferrer')
}
async function loadTasks() {
const useBlocking = tasks.value.length === 0
if (useBlocking) {
@ -215,10 +219,8 @@ onMounted(() => {
<UButton
v-if="task.status === 'succeeded'"
icon="i-lucide-download"
:to="taskDownloadUrl(task.id)"
target="_blank"
rel="noopener"
size="sm"
@click="openExportDownload(task.id)"
>
下载
</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 { dbGlobal } from "drizzle-pkg/lib/db";
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 { RELATIVE_TMP_DIR } from "#server/constants/media";
@ -24,7 +24,7 @@ function positiveBigIntFromEnv(name: string, fallback: bigint): bigint {
}
try {
const n = BigInt(raw);
return n > 0n ? n : fallback;
return n > BigInt(0) ? n : fallback;
} catch {
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_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 {
return path.resolve(process.cwd(), RELATIVE_TMP_DIR, "exports");
@ -121,8 +124,8 @@ export async function createExportTask(params: { userId: number; maskPolicy: Exp
.where(
and(
eq(userExportTasks.status, "succeeded"),
sql`${userExportTasks.expiresAt} IS NOT NULL`,
sql`${userExportTasks.expiresAt} > ${now}`,
isNotNull(userExportTasks.expiresAt),
gt(userExportTasks.expiresAt, now),
),
);
const retainedBytes = retainedRows[0]?.retainedBytes ?? "0";

Loading…
Cancel
Save