initial commit
This commit is contained in:
57
server/node_modules/firebase-admin/lib/storage/index.d.ts
generated
vendored
Normal file
57
server/node_modules/firebase-admin/lib/storage/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
/*!
|
||||
* Copyright 2020 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* Cloud Storage for Firebase.
|
||||
*
|
||||
* @packageDocumentation
|
||||
*/
|
||||
import { File } from '@google-cloud/storage';
|
||||
import { App } from '../app';
|
||||
import { Storage } from './storage';
|
||||
export { Storage } from './storage';
|
||||
/**
|
||||
* Gets the {@link Storage} service for the default app or a given app.
|
||||
*
|
||||
* `getStorage()` can be called with no arguments to access the default
|
||||
* app's `Storage` service or as `getStorage(app)` to access the
|
||||
* `Storage` service associated with a specific app.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the Storage service for the default app
|
||||
* const defaultStorage = getStorage();
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the Storage service for a given app
|
||||
* const otherStorage = getStorage(otherApp);
|
||||
* ```
|
||||
*/
|
||||
export declare function getStorage(app?: App): Storage;
|
||||
/**
|
||||
* Gets the download URL for the given {@link https://cloud.google.com/nodejs/docs/reference/storage/latest/storage/file | File}.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the downloadUrl for a given file ref
|
||||
* const storage = getStorage();
|
||||
* const myRef = ref(storage, 'images/mountains.jpg');
|
||||
* const downloadUrl = await getDownloadURL(myRef);
|
||||
* ```
|
||||
*/
|
||||
export declare function getDownloadURL(file: File): Promise<string>;
|
||||
77
server/node_modules/firebase-admin/lib/storage/index.js
generated
vendored
Normal file
77
server/node_modules/firebase-admin/lib/storage/index.js
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
"use strict";
|
||||
/*!
|
||||
* Copyright 2020 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Storage = void 0;
|
||||
exports.getStorage = getStorage;
|
||||
exports.getDownloadURL = getDownloadURL;
|
||||
const app_1 = require("../app");
|
||||
const storage_1 = require("./storage");
|
||||
const error_1 = require("../utils/error");
|
||||
const utils_1 = require("./utils");
|
||||
var storage_2 = require("./storage");
|
||||
Object.defineProperty(exports, "Storage", { enumerable: true, get: function () { return storage_2.Storage; } });
|
||||
/**
|
||||
* Gets the {@link Storage} service for the default app or a given app.
|
||||
*
|
||||
* `getStorage()` can be called with no arguments to access the default
|
||||
* app's `Storage` service or as `getStorage(app)` to access the
|
||||
* `Storage` service associated with a specific app.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the Storage service for the default app
|
||||
* const defaultStorage = getStorage();
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the Storage service for a given app
|
||||
* const otherStorage = getStorage(otherApp);
|
||||
* ```
|
||||
*/
|
||||
function getStorage(app) {
|
||||
if (typeof app === 'undefined') {
|
||||
app = (0, app_1.getApp)();
|
||||
}
|
||||
const firebaseApp = app;
|
||||
return firebaseApp.getOrInitService('storage', (app) => new storage_1.Storage(app));
|
||||
}
|
||||
/**
|
||||
* Gets the download URL for the given {@link https://cloud.google.com/nodejs/docs/reference/storage/latest/storage/file | File}.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the downloadUrl for a given file ref
|
||||
* const storage = getStorage();
|
||||
* const myRef = ref(storage, 'images/mountains.jpg');
|
||||
* const downloadUrl = await getDownloadURL(myRef);
|
||||
* ```
|
||||
*/
|
||||
async function getDownloadURL(file) {
|
||||
const endpoint = (process.env.STORAGE_EMULATOR_HOST ||
|
||||
'https://firebasestorage.googleapis.com') + '/v0';
|
||||
const { downloadTokens } = await (0, utils_1.getFirebaseMetadata)(endpoint, file);
|
||||
if (!downloadTokens) {
|
||||
throw new error_1.FirebaseError({
|
||||
code: 'storage/no-download-token',
|
||||
message: 'No download token available. Please create one in the Firebase Console.',
|
||||
});
|
||||
}
|
||||
const [token] = downloadTokens.split(',');
|
||||
return `${endpoint}/b/${file.bucket.name}/o/${encodeURIComponent(file.name)}?alt=media&token=${token}`;
|
||||
}
|
||||
45
server/node_modules/firebase-admin/lib/storage/storage-namespace.d.ts
generated
vendored
Normal file
45
server/node_modules/firebase-admin/lib/storage/storage-namespace.d.ts
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
/*!
|
||||
* Copyright 2021 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { App } from '../app';
|
||||
import { Storage as TStorage } from './storage';
|
||||
/**
|
||||
* Gets the {@link firebase-admin.storage#Storage} service for the
|
||||
* default app or a given app.
|
||||
*
|
||||
* `admin.storage()` can be called with no arguments to access the default
|
||||
* app's `Storage` service or as `admin.storage(app)` to access the
|
||||
* `Storage` service associated with a specific app.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the Storage service for the default app
|
||||
* var defaultStorage = admin.storage();
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the Storage service for a given app
|
||||
* var otherStorage = admin.storage(otherApp);
|
||||
* ```
|
||||
*/
|
||||
export declare function storage(app?: App): storage.Storage;
|
||||
export declare namespace storage {
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.storage#Storage}.
|
||||
*/
|
||||
type Storage = TStorage;
|
||||
}
|
||||
18
server/node_modules/firebase-admin/lib/storage/storage-namespace.js
generated
vendored
Normal file
18
server/node_modules/firebase-admin/lib/storage/storage-namespace.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
"use strict";
|
||||
/*!
|
||||
* Copyright 2021 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
42
server/node_modules/firebase-admin/lib/storage/storage.d.ts
generated
vendored
Normal file
42
server/node_modules/firebase-admin/lib/storage/storage.d.ts
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2017 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { App } from '../app';
|
||||
import { Bucket } from '@google-cloud/storage';
|
||||
/**
|
||||
* The default `Storage` service if no
|
||||
* app is provided or the `Storage` service associated with the provided
|
||||
* app.
|
||||
*/
|
||||
export declare class Storage {
|
||||
private readonly appInternal;
|
||||
private readonly storageClient;
|
||||
/**
|
||||
* Gets a reference to a Cloud Storage bucket.
|
||||
*
|
||||
* @param name - Optional name of the bucket to be retrieved. If name is not specified,
|
||||
* retrieves a reference to the default bucket.
|
||||
* @returns A {@link https://cloud.google.com/nodejs/docs/reference/storage/latest/Bucket | Bucket}
|
||||
* instance as defined in the `@google-cloud/storage` package.
|
||||
*/
|
||||
bucket(name?: string): Bucket;
|
||||
/**
|
||||
* Optional app whose `Storage` service to
|
||||
* return. If not provided, the default `Storage` service will be returned.
|
||||
*/
|
||||
get app(): App;
|
||||
}
|
||||
121
server/node_modules/firebase-admin/lib/storage/storage.js
generated
vendored
Normal file
121
server/node_modules/firebase-admin/lib/storage/storage.js
generated
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
"use strict";
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2017 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Storage = void 0;
|
||||
const error_1 = require("../utils/error");
|
||||
const credential_internal_1 = require("../app/credential-internal");
|
||||
const utils = require("../utils/index");
|
||||
const validator = require("../utils/validator");
|
||||
/**
|
||||
* The default `Storage` service if no
|
||||
* app is provided or the `Storage` service associated with the provided
|
||||
* app.
|
||||
*/
|
||||
class Storage {
|
||||
/**
|
||||
* @param app - The app for this Storage service.
|
||||
* @constructor
|
||||
* @internal
|
||||
*/
|
||||
constructor(app) {
|
||||
if (!validator.isNonNullObject(app) || !('options' in app)) {
|
||||
throw new error_1.FirebaseError({
|
||||
code: 'storage/invalid-argument',
|
||||
message: 'First argument passed to admin.storage() must be a valid Firebase app instance.',
|
||||
});
|
||||
}
|
||||
if (!process.env.STORAGE_EMULATOR_HOST && process.env.FIREBASE_STORAGE_EMULATOR_HOST) {
|
||||
const firebaseStorageEmulatorHost = process.env.FIREBASE_STORAGE_EMULATOR_HOST;
|
||||
if (firebaseStorageEmulatorHost.match(/https?:\/\//)) {
|
||||
throw new error_1.FirebaseError({
|
||||
code: 'storage/invalid-emulator-host',
|
||||
message: 'FIREBASE_STORAGE_EMULATOR_HOST should not contain a protocol (http or https).',
|
||||
});
|
||||
}
|
||||
process.env.STORAGE_EMULATOR_HOST = `http://${process.env.FIREBASE_STORAGE_EMULATOR_HOST}`;
|
||||
}
|
||||
let storage;
|
||||
try {
|
||||
storage = require('@google-cloud/storage').Storage;
|
||||
}
|
||||
catch (err) {
|
||||
throw new error_1.FirebaseError({
|
||||
code: 'storage/missing-dependencies',
|
||||
message: 'Failed to import the Cloud Storage client library for Node.js. '
|
||||
+ 'Make sure to install the "@google-cloud/storage" npm package. '
|
||||
+ `Original error: ${err}`,
|
||||
});
|
||||
}
|
||||
const projectId = utils.getExplicitProjectId(app);
|
||||
const credential = app.options.credential;
|
||||
if (credential instanceof credential_internal_1.ServiceAccountCredential) {
|
||||
this.storageClient = new storage({
|
||||
// When the SDK is initialized with ServiceAccountCredentials an explicit projectId is
|
||||
// guaranteed to be available.
|
||||
projectId: projectId,
|
||||
credentials: {
|
||||
private_key: credential.privateKey,
|
||||
client_email: credential.clientEmail,
|
||||
},
|
||||
});
|
||||
}
|
||||
else if ((0, credential_internal_1.isApplicationDefault)(app.options.credential)) {
|
||||
// Try to use the Google application default credentials.
|
||||
this.storageClient = new storage();
|
||||
}
|
||||
else {
|
||||
throw new error_1.FirebaseError({
|
||||
code: 'storage/invalid-credential',
|
||||
message: 'Failed to initialize Google Cloud Storage client with the available credential. ' +
|
||||
'Must initialize the SDK with a certificate credential or application default credentials ' +
|
||||
'to use Cloud Storage API.',
|
||||
});
|
||||
}
|
||||
this.appInternal = app;
|
||||
}
|
||||
/**
|
||||
* Gets a reference to a Cloud Storage bucket.
|
||||
*
|
||||
* @param name - Optional name of the bucket to be retrieved. If name is not specified,
|
||||
* retrieves a reference to the default bucket.
|
||||
* @returns A {@link https://cloud.google.com/nodejs/docs/reference/storage/latest/Bucket | Bucket}
|
||||
* instance as defined in the `@google-cloud/storage` package.
|
||||
*/
|
||||
bucket(name) {
|
||||
const bucketName = (typeof name !== 'undefined')
|
||||
? name : this.appInternal.options.storageBucket;
|
||||
if (validator.isNonEmptyString(bucketName)) {
|
||||
return this.storageClient.bucket(bucketName);
|
||||
}
|
||||
throw new error_1.FirebaseError({
|
||||
code: 'storage/invalid-argument',
|
||||
message: 'Bucket name not specified or invalid. Specify a valid bucket name via the ' +
|
||||
'storageBucket option when initializing the app, or specify the bucket name ' +
|
||||
'explicitly when calling the getBucket() method.',
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Optional app whose `Storage` service to
|
||||
* return. If not provided, the default `Storage` service will be returned.
|
||||
*/
|
||||
get app() {
|
||||
return this.appInternal;
|
||||
}
|
||||
}
|
||||
exports.Storage = Storage;
|
||||
20
server/node_modules/firebase-admin/lib/storage/utils.d.ts
generated
vendored
Normal file
20
server/node_modules/firebase-admin/lib/storage/utils.d.ts
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
import { File } from '@google-cloud/storage';
|
||||
export interface FirebaseMetadata {
|
||||
name: string;
|
||||
bucket: string;
|
||||
generation: string;
|
||||
metageneration: string;
|
||||
contentType: string;
|
||||
timeCreated: string;
|
||||
updated: string;
|
||||
storageClass: string;
|
||||
size: string;
|
||||
md5Hash: string;
|
||||
contentEncoding: string;
|
||||
contentDisposition: string;
|
||||
crc32c: string;
|
||||
etag: string;
|
||||
downloadTokens?: string;
|
||||
}
|
||||
export declare function getFirebaseMetadata(endpoint: string, file: File): Promise<FirebaseMetadata>;
|
||||
20
server/node_modules/firebase-admin/lib/storage/utils.js
generated
vendored
Normal file
20
server/node_modules/firebase-admin/lib/storage/utils.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getFirebaseMetadata = getFirebaseMetadata;
|
||||
function getFirebaseMetadata(endpoint, file) {
|
||||
const uri = `${endpoint}/b/${file.bucket.name}/o/${encodeURIComponent(file.name)}`;
|
||||
return new Promise((resolve, reject) => {
|
||||
file.storage.makeAuthenticatedRequest({
|
||||
method: 'GET',
|
||||
uri,
|
||||
}, (err, body) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
}
|
||||
else {
|
||||
resolve(body);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user