-
Notifications
You must be signed in to change notification settings - Fork 945
Storage List API #1610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Storage List API #1610
Changes from all commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
e52cc85
List API
fredzqm 974b248
Update constants.ts
fredzqm 0984bc3
always pass in prefix
fredzqm 324a7ba
Merge branch 'fz/storage-list' of github.com:firebase/firebase-js-sdk…
fredzqm 1f52804
clean up
fredzqm 29ebc7c
more tests and clean up
fredzqm 3071b84
more tests
fredzqm d1dad43
[AUTOMATED]: Prettier Code Styling
fredzqm b3585cb
fix test
fredzqm 25b6169
[AUTOMATED]: Prettier Code Styling
fredzqm bedf0f8
Update .gitignore
fredzqm 189184b
Update .gitignore
fredzqm dd8a2a7
Update constants.ts
fredzqm 99954da
Update list.ts
fredzqm 931eefd
Update reference.ts
fredzqm 1c3ab63
Merge branch 'fz/storage-list' of github.com:firebase/firebase-js-sdk…
fredzqm a11ab95
clean up
fredzqm 7e004b1
[AUTOMATED]: Prettier Code Styling
fredzqm 1bc3aee
m
fredzqm 49ec291
address comments
fredzqm 2cd9edd
[AUTOMATED]: Prettier Code Styling
fredzqm 0a86471
docs
fredzqm aa9d692
s/firebase.Promise/Promise
fredzqm ee3a184
nits
fredzqm a724f64
Merge branch 'fz/s/firebase.Promise/Promise' into fz/storage-list
fredzqm 24dfd9a
remove unecessary type annotations
fredzqm ba28dbd
Merge branch 'fz/s/firebase.Promise/Promise' into fz/list-api
fredzqm 43cde81
Merge remote-tracking branch 'origin/fz/storage-list' into fz/list-api
fredzqm 9e901d2
last round
fredzqm 4663ade
m
fredzqm b936dde
Merge remote-tracking branch 'origin/master' into fz/storage-list
fredzqm 7d8889e
m
fredzqm ae0ceca
m
fredzqm 8131c6e
Merge remote-tracking branch 'origin/master' into fz/storage-list
fredzqm e1f603c
m
fredzqm 57f2584
m
fredzqm 3935839
doc
fredzqm 336de09
m
fredzqm 8288325
more docs
fredzqm 21759f7
more doc
fredzqm b651365
Merge remote-tracking branch 'origin/master' into fz/storage-list
fredzqm 1f20d3a
add listAll
fredzqm 31fe235
[AUTOMATED]: Prettier Code Styling
fredzqm 2e052ea
doc
fredzqm 325e84f
address comments
fredzqm 8ea7bcf
m
fredzqm 324f9a9
m
fredzqm ffb3569
m
fredzqm fd6ee14
Update index.d.ts
fredzqm 035e760
Update reference.ts
fredzqm d201c91
Merge remote-tracking branch 'origin/master' into fz/storage-list
fredzqm 4015d7b
[AUTOMATED]: Prettier Code Styling
fredzqm dff0f21
change log
fredzqm 0fee0bb
mention rules version 2
fredzqm 21d5f83
Merge remote-tracking branch 'origin/master' into fz/storage-list
fredzqm 3f50d88
address comments
fredzqm 4470649
Update toc.yaml
fredzqm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- [Feature] Added the support for List API. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/** | ||
* @license | ||
* Copyright 2019 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. | ||
*/ | ||
|
||
/** | ||
* @fileoverview Documentation for the listOptions and listResult format | ||
*/ | ||
import { AuthWrapper } from './authwrapper'; | ||
import { Location } from './location'; | ||
import * as json from './json'; | ||
import * as type from './type'; | ||
import { ListResult } from '../list'; | ||
|
||
/** | ||
* Represents the simplified object metadata returned by List API. | ||
* Other fields are filtered because list in Firebase Rules does not grant | ||
* the permission to read the metadata. | ||
*/ | ||
interface ListMetadataResponse { | ||
name: string; | ||
bucket: string; | ||
} | ||
|
||
/** | ||
* Represents the JSON response of List API. | ||
*/ | ||
interface ListResultResponse { | ||
prefixes: string[]; | ||
items: ListMetadataResponse[]; | ||
nextPageToken?: string; | ||
} | ||
|
||
const MAX_RESULTS_KEY = 'maxResults'; | ||
const MAX_MAX_RESULTS = 1000; | ||
const PAGE_TOKEN_KEY = 'pageToken'; | ||
const PREFIXES_KEY = 'prefixes'; | ||
const ITEMS_KEY = 'items'; | ||
|
||
function fromBackendResponse( | ||
fredzqm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
authWrapper: AuthWrapper, | ||
resource: ListResultResponse | ||
): ListResult { | ||
const listResult: ListResult = { | ||
prefixes: [], | ||
items: [], | ||
nextPageToken: resource['nextPageToken'] | ||
}; | ||
if (resource[PREFIXES_KEY]) { | ||
for (const path of resource[PREFIXES_KEY]) { | ||
const pathWithoutTrailingSlash = path.replace(/\/$/, ''); | ||
const reference = authWrapper.makeStorageReference( | ||
new Location(authWrapper.bucket(), pathWithoutTrailingSlash) | ||
); | ||
listResult.prefixes.push(reference); | ||
} | ||
} | ||
|
||
if (resource[ITEMS_KEY]) { | ||
for (const item of resource[ITEMS_KEY]) { | ||
const reference = authWrapper.makeStorageReference( | ||
new Location(authWrapper.bucket(), item['name']) | ||
); | ||
listResult.items.push(reference); | ||
} | ||
} | ||
return listResult; | ||
} | ||
|
||
export function fromResponseString( | ||
authWrapper: AuthWrapper, | ||
resourceString: string | ||
): ListResult | null { | ||
const obj = json.jsonObjectOrNull(resourceString); | ||
if (obj === null) { | ||
return null; | ||
} | ||
const resource = obj as ListResultResponse; | ||
return fromBackendResponse(authWrapper, resource); | ||
} | ||
|
||
export function listOptionsValidator(p: any) { | ||
const validType = p && type.isObject(p); | ||
if (!validType) { | ||
throw 'Expected ListOptions object.'; | ||
} | ||
for (const key in p) { | ||
if (key === MAX_RESULTS_KEY) { | ||
if (!type.isInteger(p[MAX_RESULTS_KEY]) || p[MAX_RESULTS_KEY] <= 0) { | ||
fredzqm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
throw 'Expected maxResults to be a positive number.'; | ||
} | ||
if (p[MAX_RESULTS_KEY] > 1000) { | ||
throw `Expected maxResults to be less than or equal to ${MAX_MAX_RESULTS}.`; | ||
} | ||
} else if (key === PAGE_TOKEN_KEY) { | ||
if (p[PAGE_TOKEN_KEY] && !type.isString(p[PAGE_TOKEN_KEY])) { | ||
throw 'Expected pageToken to be string.'; | ||
} | ||
} else { | ||
throw 'Unknown option: ' + key; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* @license | ||
* Copyright 2019 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 { Reference } from './reference'; | ||
|
||
/** | ||
* @fileoverview Documentation for ListOptions and ListResult format. | ||
*/ | ||
export type ListOptions = { | ||
fredzqm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
maxResults?: number | null; | ||
pageToken?: string | null; | ||
}; | ||
|
||
export type ListResult = { | ||
prefixes: Reference[]; | ||
items: Reference[]; | ||
nextPageToken?: string | null; | ||
}; | ||
fredzqm marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.