core: export: mark pidFilter as optional

This commit is contained in:
undefined committed 2025-01-05 03:25:04 +08:00
1 parent 0771071ec2
commit 214fa2aa9d
2 files changed
+7 -4

No files matched your search

+2 -2
View File
@@ -730,8 +730,8 @@ export class ProblemFilesHandler extends ProblemDetailHandler {
files.push({
type,
name: filename,
size: statSync(this.request.files.file.filepath).size,
data: () => this.request.files.file.filepath,
size: file.size,
data: () => file.filepath,
});
}
if (!this.user.hasPriv(PRIV.PRIV_EDIT_SYSTEM)) {
+5 -2
View File
@@ -603,11 +603,14 @@ export class ProblemModel {
if (options.delSource) await fs.remove(tmpdir);
}
static async export(domainId: string, pidFilter?:string) {
static async export(domainId: string, pidFilter = '') {
console.log('Exporting problems...');
const tmpdir = path.join(os.tmpdir(), 'hydro', `${Math.random()}.export`);
await fs.mkdir(tmpdir);
const pdocs = await ProblemModel.getMulti(domainId, pidFilter ? { pid: pidFilter } : {}, ProblemModel.PROJECTION_PUBLIC).toArray();
const pdocs = await ProblemModel.getMulti(
domainId, pidFilter ? { pid: new RegExp(pidFilter) } : {},
ProblemModel.PROJECTION_PUBLIC,
).toArray();
if (process.env.HYDRO_CLI) logger.info(`Exporting ${pdocs.length} problems`);
for (const pdoc of pdocs) {
if (process.env.HYDRO_CLI) logger.info(`Exporting problem ${pdoc.pid || (`P${pdoc.docId}`)} (${pdoc.title})`);