Skip to content
Merged
Changes from all commits
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
25 changes: 21 additions & 4 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 @@ -253,28 +259,39 @@
}

/**
* Uploads a zip file to the specified bucket using the firebasestorage api.
* Uploads a zip or tar file to the specified bucket using the firebasestorage api.
*/
export async function uploadObject(
/** Source with file (name) to upload, and stream of file. */
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") {
throw new FirebaseError(`Expected a file name ending in .zip, got ${source.file}`);
switch (contentType) {
case ContentType.TAR:
if (!source.file.endsWith(".tar.gz")) {
throw new FirebaseError(`Expected a file name ending in .tar.gz, got ${source.file}`);
}
break;
default:
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",
"x-goog-content-length-range": "0,123289600",
},
body: source.stream,
Expand Down Expand Up @@ -304,7 +321,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 324 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