@itwin/object-storage-google
Version:
Object storage implementation using Google Cloud Storage
54 lines • 3.04 kB
JavaScript
;
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.GoogleFrontendStorage = void 0;
const internal_1 = require("@itwin/object-storage-core/lib/common/internal");
const frontend_1 = require("@itwin/object-storage-core/lib/frontend");
const internal_2 = require("@itwin/object-storage-core/lib/frontend/internal");
class GoogleFrontendStorage extends frontend_1.FrontendStorage {
constructor() {
super();
}
async download(input) {
if ((0, internal_1.instanceOfUrlTransferInput)(input))
return (0, internal_2.downloadFromUrlFrontend)(input);
(0, internal_1.assertRelativeDirectory)(input.reference.relativeDirectory);
const updatedInput = {
url: `https://storage.googleapis.com/storage/v1/b/${input.transferConfig.bucketName}/o/${encodeURIComponent(this.objectName(input.reference))}?alt=media`,
transferType: input.transferType,
storageType: input.transferConfig.storageType,
};
return (0, internal_2.downloadFromUrlFrontend)(updatedInput, {
Authorization: input.transferConfig.authentication,
});
}
objectName(reference) {
return (0, internal_1.buildObjectKey)(reference);
}
async upload(input) {
const { data } = input;
if ((0, internal_1.instanceOfUrlTransferInput)(input))
return (0, internal_2.uploadToUrlFrontend)(input.url, data, "PUT");
(0, internal_1.assertRelativeDirectory)(input.reference.relativeDirectory);
const url = `https://storage.googleapis.com/upload/storage/v1/b/${input.transferConfig.bucketName}/o?uploadType=media&name=${this.objectName(input.reference)}`;
return (0, internal_2.uploadToUrlFrontend)(url, input.data, "POST", {
Authorization: input.transferConfig.authentication,
"Content-Type": "application/octet-stream",
});
}
// eslint-disable-next-line @typescript-eslint/require-await
async uploadInMultipleParts(input) {
(0, internal_1.assertRelativeDirectory)(input.reference.relativeDirectory);
const url = `https://storage.googleapis.com/upload/storage/v1/b/${input.transferConfig.bucketName}/o?uploadType=media&name=${this.objectName(input.reference)}`;
const data = await (0, internal_2.streamToTransferTypeFrontend)(input.data, "buffer");
return (0, internal_2.uploadToUrlFrontend)(url, data, "POST", {
Authorization: input.transferConfig.authentication,
"Content-Type": "application/octet-stream",
});
}
}
exports.GoogleFrontendStorage = GoogleFrontendStorage;
//# sourceMappingURL=GoogleFrontendStorage.js.map