From 361cc846d259a701a875c99970d70207895e05b7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sven=20K=C3=B6nig?=
Date: Thu, 23 May 2024 14:10:24 +0200
Subject: [PATCH] StaticDatasets: adapt upload for storing geojsons
---
.../migration.sql | 12 ++++++++
db/schema.prisma | 28 +++++++++++++------
db/seeds/pmtiles.ts | 4 +--
scripts/StaticDatasets/api.ts | 2 +-
.../StaticDatasets/updateStaticDatasets.ts | 2 +-
src/app/admin/uploads/[slug]/page.tsx | 21 ++++++++++----
src/app/api/uploads/[slug]/route.ts | 2 +-
src/app/api/uploads/create/route.ts | 6 ++--
src/uploads/schema.ts | 2 +-
9 files changed, 57 insertions(+), 22 deletions(-)
create mode 100644 db/migrations/20240523105650_adapt_upload_for_storing_geojsons/migration.sql
diff --git a/db/migrations/20240523105650_adapt_upload_for_storing_geojsons/migration.sql b/db/migrations/20240523105650_adapt_upload_for_storing_geojsons/migration.sql
new file mode 100644
index 000000000..d859c6c6c
--- /dev/null
+++ b/db/migrations/20240523105650_adapt_upload_for_storing_geojsons/migration.sql
@@ -0,0 +1,12 @@
+-- CreateEnum
+CREATE TYPE "UploadCreatedByEnum" AS ENUM ('USER', 'SCRIPT');
+
+-- CreateEnum
+CREATE TYPE "UploadTypeEnum" AS ENUM ('GEOJSON', 'PMTILES');
+
+-- AlterTable
+ALTER TABLE "Upload"
+ RENAME COLUMN "pmtilesUrl" TO "url";
+ALTER TABLE "Upload"
+ ADD COLUMN "createdBy" "UploadCreatedByEnum" NOT NULL DEFAULT 'SCRIPT',
+ ADD COLUMN "type" "UploadTypeEnum" NOT NULL DEFAULT 'PMTILES';
diff --git a/db/schema.prisma b/db/schema.prisma
index f779ce3ab..5c565e54d 100644
--- a/db/schema.prisma
+++ b/db/schema.prisma
@@ -131,14 +131,26 @@ model Membership {
}
model Upload {
- id Int @id @default(autoincrement())
- createdAt DateTime @default(now())
- updatedAt DateTime @updatedAt
+ id Int @id @default(autoincrement())
+ createdAt DateTime @default(now())
+ createdBy UploadCreatedByEnum @default(SCRIPT)
+ updatedAt DateTime @updatedAt
//
- slug String @unique
- pmtilesUrl String
- configs Json
- public Boolean @default(false)
+ slug String @unique
+ type UploadTypeEnum @default(PMTILES)
+ url String
+ configs Json
+ public Boolean @default(false)
//
- regions Region[]
+ regions Region[]
+}
+
+enum UploadCreatedByEnum {
+ USER
+ SCRIPT
+}
+
+enum UploadTypeEnum {
+ GEOJSON
+ PMTILES
}
diff --git a/db/seeds/pmtiles.ts b/db/seeds/pmtiles.ts
index bbfd4ea42..b6ffe1e6c 100644
--- a/db/seeds/pmtiles.ts
+++ b/db/seeds/pmtiles.ts
@@ -16,7 +16,7 @@ const seedUploads = async () => {
const seedUploadsNudafa: Prisma.UploadUncheckedCreateInput[] = [
{
slug: 'nudafa-combined',
- pmtilesUrl:
+ url:
'https://atlas-private.s3.eu-central-1.amazonaws.com/test-data/nudafa-combined.pmtiles',
configs: [
{
@@ -39,7 +39,7 @@ const seedUploads = async () => {
const seedUploadsBibi: Prisma.UploadUncheckedCreateInput[] = [
{
slug: 'two-configs',
- pmtilesUrl:
+ url:
'https://atlas-private.s3.eu-central-1.amazonaws.com/test-data/nudafa-combined.pmtiles',
configs: [
{
diff --git a/scripts/StaticDatasets/api.ts b/scripts/StaticDatasets/api.ts
index e34408ffc..d8149f02b 100644
--- a/scripts/StaticDatasets/api.ts
+++ b/scripts/StaticDatasets/api.ts
@@ -33,7 +33,7 @@ export const getRegions = async (): Promise<{ id: number; slug: string }[]> => {
type UploadData = {
uploadSlug: string
- pmtilesUrl: string
+ url: string
regionSlugs: string[]
isPublic: boolean
configs: Record[]
diff --git a/scripts/StaticDatasets/updateStaticDatasets.ts b/scripts/StaticDatasets/updateStaticDatasets.ts
index e4fc7e9eb..dfdeab980 100644
--- a/scripts/StaticDatasets/updateStaticDatasets.ts
+++ b/scripts/StaticDatasets/updateStaticDatasets.ts
@@ -181,7 +181,7 @@ for (const { datasetFolderPath, regionFolder, datasetFolder } of datasetFileFold
})
await createUpload({
uploadSlug,
- pmtilesUrl,
+ url: pmtilesUrl,
regionSlugs,
isPublic: metaData.public,
configs: mergedConfigs,
diff --git a/src/app/admin/uploads/[slug]/page.tsx b/src/app/admin/uploads/[slug]/page.tsx
index c1a9ca854..d6322a744 100644
--- a/src/app/admin/uploads/[slug]/page.tsx
+++ b/src/app/admin/uploads/[slug]/page.tsx
@@ -57,15 +57,26 @@ export default function AdminUploadPage() {
- Vorschau für Devs (_API_KEY_
aus .env
/Bitwarden für{' '}
- {process.env.NEXT_PUBLIC_APP_ENV}
)
-
+ Datentyp: {upload.type}
+
+ {upload.type === 'GEOJSON' ? (
+
+ TODO: add link to geojson viewer
+
+ ) : (
+
+ Vorschau für Devs (_API_KEY_
aus .env
/Bitwarden für{' '}
+ {process.env.NEXT_PUBLIC_APP_ENV}
)
+
+
+ )}
+
- Öffentliche URL {getStaticDatasetUrl(upload.slug)}
+ Öffentliche URL: {getStaticDatasetUrl(upload.slug)}
- Interne URL auf S3 {upload.pmtilesUrl}
+ Interne URL: {upload.url}
{configs.map((config) => {
diff --git a/src/app/api/uploads/[slug]/route.ts b/src/app/api/uploads/[slug]/route.ts
index 315fbc0b9..2423ffaec 100644
--- a/src/app/api/uploads/[slug]/route.ts
+++ b/src/app/api/uploads/[slug]/route.ts
@@ -32,7 +32,7 @@ export async function GET(request: Request, { params }: { params: { slug: string
}
}
- const { hostname, pathname } = new URL(upload!.pmtilesUrl)
+ const { hostname, pathname } = new URL(upload!.url)
const accessKeyId = process.env.S3_KEY!
const secretAccessKey = process.env.S3_SECRET!
const region = process.env.S3_REGION!
diff --git a/src/app/api/uploads/create/route.ts b/src/app/api/uploads/create/route.ts
index 9246a38a0..acc3b4065 100644
--- a/src/app/api/uploads/create/route.ts
+++ b/src/app/api/uploads/create/route.ts
@@ -5,7 +5,7 @@ import { parseData, checkApiKey } from '../../_util/checkApiKey'
const Schema = z.object({
apiKey: z.string().nullish(),
uploadSlug: z.string(),
- pmtilesUrl: z.string(),
+ url: z.string(),
regionSlugs: z.array(z.string()),
isPublic: z.boolean(),
configs: z.array(z.record(z.string(), z.any())),
@@ -19,7 +19,7 @@ export async function POST(request: Request) {
const check = checkApiKey(data)
if (!check.ok) return check.errorResponse
- const { uploadSlug, pmtilesUrl, regionSlugs, isPublic, configs } = data
+ const { uploadSlug, url, regionSlugs, isPublic, configs } = data
await db.upload.deleteMany({ where: { slug: uploadSlug } })
@@ -27,7 +27,7 @@ export async function POST(request: Request) {
await db.upload.create({
data: {
slug: uploadSlug,
- pmtilesUrl,
+ url,
regions: { connect: regionSlugs.map((slug) => ({ slug })) },
public: isPublic,
configs,
diff --git a/src/uploads/schema.ts b/src/uploads/schema.ts
index 8c6ce8ad2..6f0f8c4da 100644
--- a/src/uploads/schema.ts
+++ b/src/uploads/schema.ts
@@ -4,7 +4,7 @@ import { RegionSchema } from '../regions/schemas'
export const UploadSchema = z.object({
id: z.number(),
slug: z.string(),
- pmtilesUrl: z.string().url(),
+ url: z.string().url(),
public: z.boolean(),
})