Skip to content

Commit

Permalink
use Google reader for gs:// URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
hpratt committed Jul 18, 2019
1 parent 544c0e5 commit 2b7f755
Show file tree
Hide file tree
Showing 4 changed files with 562 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dependencies": {
"@types/graphql": "^14.2.0",
"apollo-server-express": "^2.0.6",
"bigwig-reader": "^1.0.7",
"bigwig-reader": "^1.0.23",
"express": "^4.16.3",
"graphql": "^14.0.0"
},
Expand Down
1 change: 1 addition & 0 deletions src/models/bigwigModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface BigRequest {
end: number;
zoomLevel?: number;
preRenderedWidth?: number;
googleProject?: string;
}

export interface BigError {
Expand Down
10 changes: 8 additions & 2 deletions src/resolvers/bigwigResolver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GraphQLScalarType } from "graphql";
import { AxiosDataLoader, BigWigReader, HeaderData, FileType, ZoomLevelHeader } from "bigwig-reader";
import { AxiosDataLoader, GoogleBucketDataLoader, BigWigReader, HeaderData, FileType, ZoomLevelHeader } from "bigwig-reader";
import { BigResponse, BigResponseData, BigRequest, BigZoomData, PreRenderedBigWigData, BigWigData } from "../models/bigwigModel";

/**
Expand Down Expand Up @@ -98,7 +98,13 @@ async function condensedZoomData(data: BigZoomData[], preRenderedWidth: number,
* @param request the BigRequest to handle.
*/
async function bigRequest(request: BigRequest): Promise<BigResponse> {
const loader = new AxiosDataLoader(request.url);
const loader = request.url.startsWith("gs://") ? (
new GoogleBucketDataLoader(
request.url.split("gs://")[1].split('/')[0],
request.url.split("gs://")[1].split('/').slice(1).join('/'),
request.googleProject
)
) : new AxiosDataLoader(request.url);
const reader = new BigWigReader(loader);
const header: HeaderData = await reader.getHeader();
const zoomLevelIndex = getClosestZoomLevelIndex(request.zoomLevel, header.zoomLevelHeaders);
Expand Down
Loading

0 comments on commit 2b7f755

Please sign in to comment.