Skip to content

Commit

Permalink
fix: gs API
Browse files Browse the repository at this point in the history
  • Loading branch information
xgui3783 committed Oct 28, 2024
1 parent 8eaccc8 commit 48f3f0c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/deploy-helm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
- uses: actions/checkout@v4
- name: 'Deploy'
run: |
echo "Does not yet work. need to reconfigure TLS, hostname etc"
exit 1
kubecfg_path=${{ runner.temp }}/.kube_config
echo "${{ secrets.KUBECONFIG }}" > $kubecfg_path
Expand Down
2 changes: 1 addition & 1 deletion .helm/voluba-prod/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ version: 0.1.1
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.1.2"
appVersion: "1.1.3"
18 changes: 12 additions & 6 deletions frontend/src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,20 @@ export type TVolume = {
visibility?: 'public' | 'private' | 'custom' | 'useradded' | 'bundled'
}

export function expandUrl(url: string): string {
if (/^https?:\/\//.test(url)) {
return url
export function parseGSUrl(url: string): string {
const urlProtocolPattern = /^([^:\/]+):\/\/([^\/]+)((?:\/.*)?)$/
const match = url.match(urlProtocolPattern)
if (!match) {
throw new Error(`url does not follow the pattern {protocol}://{host}/{path}`)
}
if (/^gs:\/\//.test(url)) {
return url.replace(/^gs:\/\//, 'https://storage.googleapis.com/')
const u = {protocol: match[1], host: match[2], path: match[3]};

if (u.protocol !== "gs") {
throw new Error(`GS URL must start with gs://, but ${url} does not`)
}
throw new Error(`${url} cannot be parsed correctly`)
const path = encodeURIComponent(u.path.substring(1))
return `https://www.googleapis.com/storage/v1/b/${u.host}/o/${path}?alt=media`;

}

const protocol: Record<string, keyof Volume['providers']> = {
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/state/inputs/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createSelector, select } from '@ngrx/store';
import { nameSpace, LocalState } from './consts';
import { Observable, combineLatest, distinctUntilChanged, forkJoin, from, map, of, pipe, switchMap, throwError } from 'rxjs';
import { arrayEqual, canBeConverted, cvtToNm, expandUrl, TVolume } from 'src/const';
import { arrayEqual, canBeConverted, cvtToNm, TVolume, parseGSUrl } from 'src/const';


const featureSelector = (state: any) => state[nameSpace] as LocalState;
Expand Down Expand Up @@ -67,13 +67,12 @@ const incInfoPipe = pipe(
)
}
if (!!n5Url) {
const correctedN5Url = expandUrl(n5Url)
return forkJoin([
fetch(
`${correctedN5Url}/attributes.json`
parseGSUrl(`${n5Url}/attributes.json`)
).then(res => res.json() as Promise<{ resolution: number[], units: string[] }>),
fetch(
`${correctedN5Url}/s0/attributes.json`
parseGSUrl(`${n5Url}/s0/attributes.json`)
).then(res => res.json() as Promise<{ blockSize: number[], dimensions: number[] }>),
]).pipe(
map(([root, s0]) => {
Expand Down

0 comments on commit 48f3f0c

Please sign in to comment.