Skip to content

Commit

Permalink
Data downloads!
Browse files Browse the repository at this point in the history
  • Loading branch information
underbluewaters committed Feb 2, 2024
1 parent be7ad91 commit 8745fdd
Show file tree
Hide file tree
Showing 13 changed files with 1,231 additions and 204 deletions.
25 changes: 25 additions & 0 deletions packages/api/generated-schema-clean.gql
Original file line number Diff line number Diff line change
Expand Up @@ -3053,6 +3053,15 @@ enum DataSourceTypes {
VIDEO
}

enum DataUploadOutputType {
FLAT_GEOBUF
GEO_JSON
GEO_TIFF
PMTILES
PNG
ZIPPED_SHAPEFILE
}

enum DataUploadState {
AWAITING_UPLOAD
CARTOGRAPHY
Expand Down Expand Up @@ -4647,6 +4656,13 @@ type DismissFailedUploadPayload {
query: Query
}

type DownloadOption {
isOriginal: Boolean
size: BigInt
type: DataUploadOutputType
url: String
}

scalar Email

"""
Expand Down Expand Up @@ -13218,6 +13234,15 @@ type TableOfContentsItem implements Node {
If is_folder=false, a DataLayers visibility will be controlled by this item
"""
dataLayerId: Int

"""Reads and enables pagination through a set of `DownloadOption`."""
downloadOptions(
"""Only read the first `n` values of the set."""
first: Int

"""Skip the first `n` values."""
offset: Int
): [DownloadOption!]
enableDownload: Boolean!
ftsAr: String
ftsDa: String
Expand Down
25 changes: 25 additions & 0 deletions packages/api/generated-schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -3053,6 +3053,15 @@ enum DataSourceTypes {
VIDEO
}

enum DataUploadOutputType {
FLAT_GEOBUF
GEO_JSON
GEO_TIFF
PMTILES
PNG
ZIPPED_SHAPEFILE
}

enum DataUploadState {
AWAITING_UPLOAD
CARTOGRAPHY
Expand Down Expand Up @@ -4647,6 +4656,13 @@ type DismissFailedUploadPayload {
query: Query
}

type DownloadOption {
isOriginal: Boolean
size: BigInt
type: DataUploadOutputType
url: String
}

scalar Email

"""
Expand Down Expand Up @@ -13218,6 +13234,15 @@ type TableOfContentsItem implements Node {
If is_folder=false, a DataLayers visibility will be controlled by this item
"""
dataLayerId: Int

"""Reads and enables pagination through a set of `DownloadOption`."""
downloadOptions(
"""Only read the first `n` values of the set."""
first: Int

"""Skip the first `n` values."""
offset: Int
): [DownloadOption!]
enableDownload: Boolean!
ftsAr: String
ftsDa: String
Expand Down
41 changes: 41 additions & 0 deletions packages/api/migrations/committed/000292.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--! Previous: sha1:d70db66b6510ada0a863d3d17bb89203fd3c8036
--! Hash: sha1:dd418c91588b73943d5eabd3430341febd583459

-- Enter migration here

drop function if exists table_of_contents_items_download_options(item table_of_contents_items) cascade;
drop type if exists download_option cascade;
create type download_option as (
type data_upload_output_type,
url text,
is_original boolean,
size bigint
);

create or replace function table_of_contents_items_download_options(item table_of_contents_items)
returns setof download_option
language sql
stable
security definer
as $$
select
type,
(case when is_original then
replace(url, 'tiles.seasketch.org', 'uploads.seasketch.org') || '?download=' || original_filename
else
replace(url, 'tiles.seasketch.org', 'uploads.seasketch.org') || '?download=' || substring(original_filename from '(.*)\.\w+$') || substring(url from '.*(\.\w+)$')
end) as url,
is_original,
size
from
data_upload_outputs
where
data_upload_outputs.data_source_id = (
select data_source_id from data_layers where data_layers.id = item.data_layer_id
);
$$;

grant execute on function table_of_contents_items_download_options(table_of_contents_items) to anon;


comment on function table_of_contents_items_download_options(table_of_contents_items) is '@simpleCollections only';
Loading

0 comments on commit 8745fdd

Please sign in to comment.