Skip to content

Commit b4ee48b

Browse files
committed
refactor(storage): implement interceptor support in isPublic method
1 parent 29d2ecf commit b4ee48b

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

handwritten/storage/src/file.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3315,9 +3315,16 @@ class File extends ServiceObject<File, FileMetadata> {
33153315
undefined,
33163316
callback,
33173317
);
3318-
const url = `${this.storage.apiEndpoint}/${this.bucket.name}/${encodeURIComponent(this.name)}`;
3318+
const url = `https://${this.storage.apiEndpoint}/storage/v1/b/${this.bucket.name}/o/${encodeURIComponent(this.name)}`;
33193319

33203320
const gaxios = new Gaxios();
3321+
const storageInterceptors = this.storage?.interceptors || [];
3322+
const fileInterceptors = this.interceptors || [];
3323+
const allInterceptors = storageInterceptors.concat(fileInterceptors);
3324+
3325+
for (const curInter of allInterceptors) {
3326+
gaxios.interceptors.request.add(curInter);
3327+
}
33213328
gaxios
33223329
.request({
33233330
method: 'GET',

handwritten/storage/src/iam.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ class Iam {
462462
? permissions
463463
: [permissions];
464464

465-
const req: any = {
465+
const req: {permissions: string[]; userProject?: string} = {
466466
permissions: permissionsArray,
467467
};
468468
if (options.userProject) {

handwritten/storage/test/file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3744,7 +3744,7 @@ describe('File', () => {
37443744

37453745
it('should correctly format URL and method in the request', done => {
37463746
gaxiosStub.resolves({data: {}});
3747-
const expectedUrl = `${file.storage.apiEndpoint}/${BUCKET.name}/${encodeURIComponent(file.name)}`;
3747+
const expectedUrl = `https://${file.storage.apiEndpoint}/storage/v1/b/${BUCKET.name}/o/${encodeURIComponent(file.name)}`;
37483748

37493749
file.isPublic(err => {
37503750
assert.ifError(err);

0 commit comments

Comments
 (0)