Skip to content
\n
\n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n
export async function addTestdata(domainId: string, pid: number, name: string, f: Readable | Buffer | string) {
const [[, fileinfo]] = await Promise.all([
document.getSub(domainId, document.TYPE_PROBLEM, pid, 'data', name),
storage.put(`problem/${domainId}/${pid}/testdata/${name}`, f),
]);
const meta = await storage.getMeta(`problem/${domainId}/${pid}/testdata/${name}`);
const payload = { name, ...pick(meta, ['size', 'lastModified', 'etag']) };
if (!fileinfo) await push(domainId, pid, 'data', { _id: name, ...payload });
else await document.setSub(domainId, document.TYPE_PROBLEM, pid, 'data', name, payload);
}
\n
\n
\n

","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"

Solved it! Just made a function that only gets and sets the metadata.

\n
async function setTestdata(domainId, pid, name) {\n    const [[, fileinfo]] = await Promise.all([\n        document.getSub(domainId, document.TYPE_PROBLEM, pid, 'data', name),\n    ]);\n    const meta = await storage_1.default.getMetaCli(`problem/${domainId}/${pid}/testdata/${name}`);\n    const payload = { name, ...lodash_1.pick(meta, ['size', 'lastModified', 'etag']) };\n    await push(domainId, pid, 'data', { _id: name, ...payload });\n}\nexports.setTestdata = setTestdata;
\n

Like this.

","upvoteCount":1,"url":"https://GitHub.com/hydro-dev/Hydro/discussions/52#discussioncomment-367574"}}}

Etag restoration #52

Answered by junukwon7
junukwon7 asked this question in Q&A
Feb 14, 2021 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Solved it! Just made a function that only gets and sets the metadata.

async function setTestdata(domainId, pid, name) {
    const [[, fileinfo]] = await Promise.all([
        document.getSub(domainId, document.TYPE_PROBLEM, pid, 'data', name),
    ]);
    const meta = await storage_1.default.getMetaCli(`problem/${domainId}/${pid}/testdata/${name}`);
    const payload = { name, ...lodash_1.pick(meta, ['size', 'lastModified', 'etag']) };
    await push(domainId, pid, 'data', { _id: name, ...payload });
}
exports.setTestdata = setTestdata;

Like this.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@undefined-moe
Comment options

Answer selected by junukwon7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants