Skip to content

Commit 5ec092a

Browse files
committed
wip
1 parent 4f821d9 commit 5ec092a

File tree

3 files changed

+210
-146
lines changed

3 files changed

+210
-146
lines changed

packages/storage/src/reference.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export async function uploadBytes(
136136
): Promise<UploadTaskNonResumableSnapshot> {
137137
ref._throwIfRoot('uploadBytes');
138138
const authToken = await ref.storage.getAuthToken();
139-
const requestInfo = fbsRequests.multipartUpload(
139+
const requestInfo = fbsRequests.simpleUpload(
140140
ref.storage,
141141
ref._location,
142142
getMappings(),
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { initializeApp } from '@firebase/app-exp';
19+
import { getAuth, signInAnonymously } from '@firebase/auth-exp';
20+
// import { getStorage, ref, uploadBytes } from '../../exp/index';
21+
22+
// See https://github.com/typescript-eslint/typescript-eslint/issues/363
23+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
24+
// import * as storage from '@firebase/storage-types';
25+
26+
// import { expect } from 'chai';
27+
// import { StorageService } from '../../src/service';
28+
29+
// eslint-disable-next-line @typescript-eslint/no-require-imports
30+
const PROJECT_CONFIG = require('../../../../config/project.json');
31+
32+
export const PROJECT_ID = PROJECT_CONFIG.projectId;
33+
export const STORAGE_BUCKET = PROJECT_CONFIG.storageBucket;
34+
export const API_KEY = PROJECT_CONFIG.apiKey;
35+
36+
let appCount = 0;
37+
38+
// export async function withTestInstance(
39+
// fn: (storage: StorageService) => void | Promise<void>
40+
// ): Promise<void> {
41+
// const app = initializeApp(
42+
// { apiKey: API_KEY, projectId: PROJECT_ID, storageBucket: STORAGE_BUCKET },
43+
// 'test-app-' + appCount++
44+
// );
45+
// await signInAnonymously(getAuth(app));
46+
// // const storage = getStorage(app);
47+
// // return fn(storage);
48+
// }
49+
50+
describe.only('FirebaseStorage', () => {
51+
it('can upload bytes', async () => {
52+
const app = initializeApp(
53+
{ apiKey: API_KEY, projectId: PROJECT_ID, storageBucket: STORAGE_BUCKET },
54+
'test-app-' + appCount++
55+
);
56+
await signInAnonymously(getAuth(app));
57+
console.log('signed in!');
58+
// return withTestInstance(async storage => {
59+
// console.log('got it!');
60+
// const reference = ref(storage, 'public/bytes');
61+
// await uploadBytes(reference, new Uint8Array([0, 1, 3]));
62+
// });
63+
});
64+
});
Lines changed: 145 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -1,145 +1,145 @@
1-
/**
2-
* @license
3-
* Copyright 2020 Google LLC
4-
*
5-
* Licensed under the Apache License, Version 2.0 (the "License");
6-
* you may not use this file except in compliance with the License.
7-
* You may obtain a copy of the License at
8-
*
9-
* http://www.apache.org/licenses/LICENSE-2.0
10-
*
11-
* Unless required by applicable law or agreed to in writing, software
12-
* distributed under the License is distributed on an "AS IS" BASIS,
13-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
* See the License for the specific language governing permissions and
15-
* limitations under the License.
16-
*/
17-
18-
import firebase from '@firebase/app';
19-
import '@firebase/auth';
20-
21-
// See https://github.com/typescript-eslint/typescript-eslint/issues/363
22-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
23-
import * as storage from '@firebase/storage-types';
24-
25-
import { expect } from 'chai';
26-
import '../../compat/index';
27-
28-
// eslint-disable-next-line @typescript-eslint/no-require-imports
29-
const PROJECT_CONFIG = require('../../../../config/project.json');
30-
31-
export const PROJECT_ID = PROJECT_CONFIG.projectId;
32-
export const STORAGE_BUCKET = PROJECT_CONFIG.storageBucket;
33-
export const API_KEY = PROJECT_CONFIG.apiKey;
34-
35-
let appCount = 0;
36-
37-
export async function withTestInstance(
38-
fn: (storage: storage.FirebaseStorage) => void | Promise<void>
39-
): Promise<void> {
40-
const app = firebase.initializeApp(
41-
{ apiKey: API_KEY, projectId: PROJECT_ID, storageBucket: STORAGE_BUCKET },
42-
'test-app-' + appCount++
43-
);
44-
await firebase.auth!(app).signInAnonymously();
45-
const storage = firebase.storage!(app);
46-
return fn(storage);
47-
}
48-
49-
describe('FirebaseStorage', () => {
50-
it('can upload bytes', () => {
51-
return withTestInstance(async storage => {
52-
const ref = storage.ref('public/bytes');
53-
await ref.put(new Uint8Array([0, 1, 3]));
54-
});
55-
});
56-
57-
it('can upload string', () => {
58-
return withTestInstance(async storage => {
59-
const ref = storage.ref('public/string');
60-
await ref.putString('foo');
61-
});
62-
});
63-
64-
it('validates operations on root', () => {
65-
return withTestInstance(async storage => {
66-
const ref = storage.ref('');
67-
try {
68-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
69-
ref.putString('foo');
70-
expect.fail();
71-
} catch (e) {
72-
expect(e.message).to.satisfy((v: string) =>
73-
v.match(
74-
/The operation 'putString' cannot be performed on a root reference/
75-
)
76-
);
77-
}
78-
});
79-
});
80-
81-
it('can delete object ', () => {
82-
return withTestInstance(async storage => {
83-
const ref = storage.ref('public/delete');
84-
await ref.putString('foo');
85-
86-
// getDownloadURL() succeeds for an existing object
87-
await ref.getDownloadURL();
88-
89-
await ref.delete();
90-
try {
91-
// getDownloadURL() fails for a deleted object
92-
await ref.getDownloadURL();
93-
expect.fail();
94-
} catch (e) {
95-
expect(e.message).to.satisfy((v: string) =>
96-
v.match(/Object 'public\/delete' does not exist/)
97-
);
98-
}
99-
});
100-
});
101-
102-
it('can get download URL', () => {
103-
return withTestInstance(async storage => {
104-
const ref = storage.ref('public/downloadurl');
105-
await ref.put(new Uint8Array([0, 1, 3]));
106-
const url = await ref.getDownloadURL();
107-
expect(url).to.satisfy((v: string) =>
108-
v.match(
109-
/https:\/\/firebasestorage\.googleapis\.com\/v0\/b\/.*\/o\/public%2Fdownloadurl/
110-
)
111-
);
112-
});
113-
});
114-
115-
it('can get metadata', () => {
116-
return withTestInstance(async storage => {
117-
const ref = storage.ref('public/getmetadata');
118-
await ref.put(new Uint8Array([0, 1, 3]));
119-
const metadata = await ref.getMetadata();
120-
expect(metadata.name).to.equal('getmetadata');
121-
});
122-
});
123-
124-
it('can update metadata', () => {
125-
return withTestInstance(async storage => {
126-
const ref = storage.ref('public/updatemetadata');
127-
await ref.put(new Uint8Array([0, 1, 3]));
128-
const metadata = await ref.updateMetadata({
129-
customMetadata: { foo: 'bar' }
130-
});
131-
expect(metadata.customMetadata).to.deep.equal({ foo: 'bar' });
132-
});
133-
});
134-
135-
it('can list files', () => {
136-
return withTestInstance(async storage => {
137-
await storage.ref('public/list/a').putString('');
138-
await storage.ref('public/list/b').putString('');
139-
await storage.ref('public/list/c/d').putString('');
140-
const listResult = await storage.ref('public/list').listAll();
141-
expect(listResult.items.map(v => v.name)).to.have.members(['a', 'b']);
142-
expect(listResult.prefixes.map(v => v.name)).to.have.members(['c']);
143-
});
144-
});
145-
});
1+
// /**
2+
// * @license
3+
// * Copyright 2020 Google LLC
4+
// *
5+
// * Licensed under the Apache License, Version 2.0 (the "License");
6+
// * you may not use this file except in compliance with the License.
7+
// * You may obtain a copy of the License at
8+
// *
9+
// * http://www.apache.org/licenses/LICENSE-2.0
10+
// *
11+
// * Unless required by applicable law or agreed to in writing, software
12+
// * distributed under the License is distributed on an "AS IS" BASIS,
13+
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// * See the License for the specific language governing permissions and
15+
// * limitations under the License.
16+
// */
17+
18+
// import firebase from '@firebase/app';
19+
// import '@firebase/auth';
20+
21+
// // See https://github.com/typescript-eslint/typescript-eslint/issues/363
22+
// // eslint-disable-next-line @typescript-eslint/no-unused-vars
23+
// import * as storage from '@firebase/storage-types';
24+
25+
// import { expect } from 'chai';
26+
// import '../../compat/index';
27+
28+
// // eslint-disable-next-line @typescript-eslint/no-require-imports
29+
// const PROJECT_CONFIG = require('../../../../config/project.json');
30+
31+
// export const PROJECT_ID = PROJECT_CONFIG.projectId;
32+
// export const STORAGE_BUCKET = PROJECT_CONFIG.storageBucket;
33+
// export const API_KEY = PROJECT_CONFIG.apiKey;
34+
35+
// let appCount = 0;
36+
37+
// export async function withTestInstance(
38+
// fn: (storage: storage.FirebaseStorage) => void | Promise<void>
39+
// ): Promise<void> {
40+
// const app = firebase.initializeApp(
41+
// { apiKey: API_KEY, projectId: PROJECT_ID, storageBucket: STORAGE_BUCKET },
42+
// 'test-app-' + appCount++
43+
// );
44+
// await firebase.auth!(app).signInAnonymously();
45+
// const storage = firebase.storage!(app);
46+
// return fn(storage);
47+
// }
48+
49+
// describe('FirebaseStorage', () => {
50+
// it('can upload bytes', () => {
51+
// return withTestInstance(async storage => {
52+
// const ref = storage.ref('public/bytes');
53+
// await ref.put(new Uint8Array([0, 1, 3]));
54+
// });
55+
// });
56+
57+
// it('can upload string', () => {
58+
// return withTestInstance(async storage => {
59+
// const ref = storage.ref('public/string');
60+
// await ref.putString('foo');
61+
// });
62+
// });
63+
64+
// it('validates operations on root', () => {
65+
// return withTestInstance(async storage => {
66+
// const ref = storage.ref('');
67+
// try {
68+
// // eslint-disable-next-line @typescript-eslint/no-floating-promises
69+
// ref.putString('foo');
70+
// expect.fail();
71+
// } catch (e) {
72+
// expect(e.message).to.satisfy((v: string) =>
73+
// v.match(
74+
// /The operation 'putString' cannot be performed on a root reference/
75+
// )
76+
// );
77+
// }
78+
// });
79+
// });
80+
81+
// it('can delete object ', () => {
82+
// return withTestInstance(async storage => {
83+
// const ref = storage.ref('public/delete');
84+
// await ref.putString('foo');
85+
86+
// // getDownloadURL() succeeds for an existing object
87+
// await ref.getDownloadURL();
88+
89+
// await ref.delete();
90+
// try {
91+
// // getDownloadURL() fails for a deleted object
92+
// await ref.getDownloadURL();
93+
// expect.fail();
94+
// } catch (e) {
95+
// expect(e.message).to.satisfy((v: string) =>
96+
// v.match(/Object 'public\/delete' does not exist/)
97+
// );
98+
// }
99+
// });
100+
// });
101+
102+
// it('can get download URL', () => {
103+
// return withTestInstance(async storage => {
104+
// const ref = storage.ref('public/downloadurl');
105+
// await ref.put(new Uint8Array([0, 1, 3]));
106+
// const url = await ref.getDownloadURL();
107+
// expect(url).to.satisfy((v: string) =>
108+
// v.match(
109+
// /https:\/\/firebasestorage\.googleapis\.com\/v0\/b\/.*\/o\/public%2Fdownloadurl/
110+
// )
111+
// );
112+
// });
113+
// });
114+
115+
// it('can get metadata', () => {
116+
// return withTestInstance(async storage => {
117+
// const ref = storage.ref('public/getmetadata');
118+
// await ref.put(new Uint8Array([0, 1, 3]));
119+
// const metadata = await ref.getMetadata();
120+
// expect(metadata.name).to.equal('getmetadata');
121+
// });
122+
// });
123+
124+
// it('can update metadata', () => {
125+
// return withTestInstance(async storage => {
126+
// const ref = storage.ref('public/updatemetadata');
127+
// await ref.put(new Uint8Array([0, 1, 3]));
128+
// const metadata = await ref.updateMetadata({
129+
// customMetadata: { foo: 'bar' }
130+
// });
131+
// expect(metadata.customMetadata).to.deep.equal({ foo: 'bar' });
132+
// });
133+
// });
134+
135+
// it('can list files', () => {
136+
// return withTestInstance(async storage => {
137+
// await storage.ref('public/list/a').putString('');
138+
// await storage.ref('public/list/b').putString('');
139+
// await storage.ref('public/list/c/d').putString('');
140+
// const listResult = await storage.ref('public/list').listAll();
141+
// expect(listResult.items.map(v => v.name)).to.have.members(['a', 'b']);
142+
// expect(listResult.prefixes.map(v => v.name)).to.have.members(['c']);
143+
// });
144+
// });
145+
// });

0 commit comments

Comments
 (0)