MCPcopy Create free account
hub / github.com/hydro-dev/Hydro / copy

Method copy

packages/hydrooj/src/model/storage.ts:139–157  ·  view source on GitHub ↗
(src: string, dst: string)

Source from the content-addressed store, hash-verified

137 }
138
139 static async copy(src: string, dst: string) {
140 const value = await StorageModel.coll.findOneAndUpdate(
141 { path: src, autoDelete: null },
142 { $set: { lastUsage: new Date() } },
143 { returnDocument: 'after' },
144 );
145 if (!value) throw new Error(`Original file ${src} not found`);
146 const meta = {};
147 await StorageModel.del([dst]);
148 meta['Content-Type'] = mime(dst);
149 let _id = StorageModel.generateId(extname(dst));
150 // Make sure id is not used
151 // eslint-disable-next-line no-await-in-loop
152 while (await StorageModel.coll.findOne({ _id })) _id = StorageModel.generateId(extname(dst));
153 await StorageModel.coll.insertOne({
154 ...value, _id, path: dst, link: value.link || value._id, lastModified: new Date(), owner: value.owner || 1,
155 });
156 return _id;
157 }
158}
159
160async function cleanFiles() {

Callers 4

getProblemFunction · 0.45
applyFunction · 0.45
postCopyMethod · 0.45
index.jsFile · 0.45

Calls 3

mimeFunction · 0.85
generateIdMethod · 0.80
delMethod · 0.45

Tested by

no test coverage detected