Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/gcp/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
import * as utils from "../utils";
import { fieldMasks } from "./proto";

/** Content Type **/

Check warning on line 14 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Should be no multiple asterisks on end lines
export enum ContentType {
ZIP = "ZIP",
TAR = "TAR",
}

/** Bucket Interface */
interface BucketResponse {
kind: string;
Expand Down Expand Up @@ -195,7 +201,7 @@
downloadTokens?: string;
}

export async function getDefaultBucket(projectId: string): Promise<string> {

Check warning on line 204 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
await ensure(projectId, firebaseStorageOrigin(), "storage", false);
try {
const localAPIClient = new Client({
Expand All @@ -211,9 +217,9 @@
"Your project is being set up. Please wait a minute before deploying again.",
);
}
return response.body.bucket.name.split("/").pop()!;

Check warning on line 220 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Forbidden non-null assertion
} catch (err: any) {

Check warning on line 221 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
if (err?.status === 404) {

Check warning on line 222 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .status on an `any` value
throw new FirebaseError(
`Firebase Storage has not been set up on project '${clc.bold(
projectId,
Expand All @@ -225,8 +231,8 @@
}
}

export async function upload(

Check warning on line 234 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
source: any,

Check warning on line 235 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
uploadUrl: string,
extraHeaders?: Record<string, string>,
ignoreQuotaProject?: boolean,
Expand All @@ -243,7 +249,7 @@
"content-type": "application/zip",
...extraHeaders,
},
body: source.stream,

Check warning on line 252 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .stream on an `any` value

Check warning on line 252 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
skipLog: { resBody: true },
ignoreQuotaProject,
});
Expand All @@ -252,6 +258,7 @@
};
}


Check failure on line 261 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / unit (24)

Delete `⏎`

Check failure on line 261 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Delete `⏎`

Check failure on line 261 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / unit (24)

Delete `⏎`

Check failure on line 261 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / unit (20)

Delete `⏎`
/**
* Uploads a zip file to the specified bucket using the firebasestorage api.
*/
Expand All @@ -260,21 +267,27 @@
source: { file: string; stream: Readable },
/** Bucket to upload to. */
bucketName: string,
contentType?: ContentType,
): Promise<{
bucket: string;
object: string;
generation: string | null;
}> {
if (path.extname(source.file) !== ".zip") {
if (contentType == ContentType.TAR) {

Check failure on line 276 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / unit (24)

Expected '===' and instead saw '=='

Check failure on line 276 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Expected '===' and instead saw '=='

Check failure on line 276 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / unit (24)

Expected '===' and instead saw '=='

Check failure on line 276 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / unit (20)

Expected '===' and instead saw '=='
if (path.extname(source.file) !== ".tar.gz") {
throw new FirebaseError(`Expected a file name ending in .tar.gz, got ${source.file}`);
}
} else if (path.extname(source.file) !== ".zip") {
throw new FirebaseError(`Expected a file name ending in .zip, got ${source.file}`);
}

const localAPIClient = new Client({ urlPrefix: storageOrigin() });
const location = `/${bucketName}/${path.basename(source.file)}`;
const res = await localAPIClient.request({
method: "PUT",
path: location,
headers: {
"Content-Type": "application/zip",
"Content-Type": contentType == ContentType.TAR ? "application/octet-stream" : "application/zip",

Check failure on line 290 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / unit (24)

Expected '===' and instead saw '=='

Check failure on line 290 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / unit (24)

Insert `⏎·······`

Check failure on line 290 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Expected '===' and instead saw '=='

Check failure on line 290 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Insert `⏎·······`

Check failure on line 290 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / unit (24)

Expected '===' and instead saw '=='

Check failure on line 290 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / unit (24)

Insert `⏎·······`

Check failure on line 290 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / unit (20)

Expected '===' and instead saw '=='

Check failure on line 290 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / unit (20)

Insert `⏎·······`
"x-goog-content-length-range": "0,123289600",
},
body: source.stream,
Expand Down Expand Up @@ -304,7 +317,7 @@
* Deletes an object via Firebase Storage.
* @param {string} location A Firebase Storage location, of the form "/v0/b/<bucket>/o/<object>"
*/
export function deleteObject(location: string): Promise<any> {

Check warning on line 320 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
const localAPIClient = new Client({ urlPrefix: storageOrigin() });
return localAPIClient.delete(location);
}
Expand Down
Loading