diff --git a/README.md b/README.md index 90b48f9..f89485a 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,6 @@ The total quota for each project is simply calculated by `(CURRENT_YEAR - year) Each project's current usage is tracked in `{project}/..usage`, which contains a JSON object with the following properties: - `total`: the total number of bytes allocated to user-supplied files (i.e., not including `..`-prefixed internal files). -- `~pending_on_complete_only` (optional): internal use only, this should be ignored by readers. ## Interacting with the API diff --git a/src/upload.js b/src/upload.js index 73471cd..bdf8ff7 100644 --- a/src/upload.js +++ b/src/upload.js @@ -211,8 +211,6 @@ function checkBadName(name, type) { } } -const pending_name = "~pending_on_complete_only"; - export async function initializeUploadHandler(request, env, nonblockers) { let project = decodeURIComponent(request.params.project); let asset = decodeURIComponent(request.params.asset); @@ -275,9 +273,7 @@ export async function initializeUploadHandler(request, env, nonblockers) { } let link_details = await checkLinks(split.link, project, asset, version, env, manifest_cache); - // Checking that the quota isn't exceeded. Note that 'pending_name' - // should only EVER be used by completeUploadHandler, so even if it's - // non-zero here, we just ignore it. + // Checking that the quota isn't exceeded. let current_usage = 0; for (const s of split.simple) { current_usage += s.size; @@ -289,9 +285,6 @@ export async function initializeUploadHandler(request, env, nonblockers) { throw new http.HttpError("upload exceeds the storage quota for this project", 400); } - usage[pending_name] = current_usage; - bucket_writes.push(s3.quickUploadJson(upath, usage, env)); - // Build a manifest for inspection. let manifest = {}; for (const s of split.simple) { @@ -400,7 +393,9 @@ export async function completeUploadHandler(request, env, nonblockers) { // We scan the manifest to check that all files were uploaded. We also // collect links for some more work later. let manifest = await assets.manifest; + let added_usage = 0; let linkable = {}; + for (const [k, v] of Object.entries(manifest)) { let s = assets.listing.get(k); let found = (typeof s != "undefined"); @@ -427,6 +422,7 @@ export async function completeUploadHandler(request, env, nonblockers) { } else if (s != v.size) { throw new http.HttpError("actual size of '" + k + "' does not match its reported size in the manifest", 400); } + added_usage += s; } } @@ -449,8 +445,7 @@ export async function completeUploadHandler(request, env, nonblockers) { // Updating the usage file. let upath = pkeys.usage(project); let usage = await s3.quickFetchJson(upath, env); - usage.total += usage[pending_name]; - delete usage[pending_name] + usage.total += added_usage; bucket_writes.push(s3.quickUploadJson(upath, usage, env)); if (is_official) { diff --git a/tests/upload.test.js b/tests/upload.test.js index c2e1145..af6117c 100644 --- a/tests/upload.test.js +++ b/tests/upload.test.js @@ -197,11 +197,6 @@ test("initializeUploadHandler works correctly for simple uploads", async () => { expect(typeof lckbody.session_hash).toEqual("string"); expect(lckbody.version).toEqual("v0"); - // Check that the usage file was updated. - let usinfo = await env.BOUND_BUCKET.get("test-upload/..usage"); - let usbody = await usinfo.json(); - expect(usbody["~pending_on_complete_only"]).toEqual(123); - // Check that a version summary file was posted to the bucket. let sinfo = await env.BOUND_BUCKET.get("test-upload/blob/v0/..summary"); let sbody = await sinfo.json(); @@ -747,7 +742,11 @@ test("completeUploadHandler works correctly", async () => { // Checking that the usage has been updated. let usinfo = await env.BOUND_BUCKET.get("test-upload/..usage"); let usbody = await usinfo.json(); - expect(usbody.total).toBeGreaterThan(original_size); + let new_size = original_size; + for (const x of [ "makoto", "akane", "chito" ]) { //i.e., everything set as 'simple'. + new_size += payload[x].length; + } + expect(usbody.total).toEqual(new_size); // Check that a log was added. let found_logs = await setup.fetchLogs(env);