Enable E-Tags for GUI and RAW

This commit is contained in:
Fabian Stamm
2020-08-02 16:33:41 +02:00
parent 5337b44b11
commit cece103504
7 changed files with 86 additions and 52 deletions

View File

@ -95,7 +95,7 @@ export async function getFile(
pkgName: string,
version: string | null | undefined,
file: string
): Promise<Uint8Array | null | undefined> {
): Promise<{ etag: string; data: Uint8Array } | null | undefined> {
const meta = await db.package.findOne({ name: pkgName });
if (!meta || meta.versions.length < 1) return null;
@ -122,8 +122,12 @@ export async function getFile(
console.log("Getting file from:", bucketPath);
try {
const data = (await bucket.getObject(bucketPath))?.body;
return data;
const res = await bucket.getObject(bucketPath);
if (!res) return undefined;
return {
etag: res.etag,
data: res.body,
};
} catch (err) {
const msg = err.message as string;
if (msg.indexOf("404") >= 0) return null;