mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-23 00:37:47 +00:00
fix: use string content type instead of enum (#7007)
Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
parent
187c489b2c
commit
385bd572a3
@ -3,12 +3,10 @@ CREATE SCHEMA IF NOT EXISTS blob;
|
|||||||
|
|
||||||
DROP TABLE IF EXISTS blob.blob;
|
DROP TABLE IF EXISTS blob.blob;
|
||||||
DROP TABLE IF EXISTS blob.data;
|
DROP TABLE IF EXISTS blob.data;
|
||||||
DROP TYPE IF EXISTS blob.content_type;
|
|
||||||
DROP TYPE IF EXISTS blob.location;
|
DROP TYPE IF EXISTS blob.location;
|
||||||
|
|
||||||
-- B L O B
|
-- B L O B
|
||||||
|
|
||||||
CREATE TYPE blob.content_type AS ENUM ('application','audio','font','image','model','text','video');
|
|
||||||
CREATE TYPE blob.location AS ENUM ('kv', 'weur', 'eeur', 'wnam', 'enam', 'apac');
|
CREATE TYPE blob.location AS ENUM ('kv', 'weur', 'eeur', 'wnam', 'enam', 'apac');
|
||||||
|
|
||||||
\echo "Creating blob.data..."
|
\echo "Creating blob.data..."
|
||||||
@ -17,8 +15,7 @@ CREATE TABLE blob.data (
|
|||||||
location blob.location NOT NULL,
|
location blob.location NOT NULL,
|
||||||
size INT8 NOT NULL,
|
size INT8 NOT NULL,
|
||||||
filename UUID NOT NULL,
|
filename UUID NOT NULL,
|
||||||
type blob.content_type NOT NULL,
|
type STRING(255) NOT NULL,
|
||||||
subtype STRING(64) NOT NULL,
|
|
||||||
CONSTRAINT pk_data PRIMARY KEY (hash, location)
|
CONSTRAINT pk_data PRIMARY KEY (hash, location)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -163,7 +163,6 @@ async function saveBlob (
|
|||||||
const { location, bucket } = selectStorage(env, workspace)
|
const { location, bucket } = selectStorage(env, workspace)
|
||||||
|
|
||||||
const size = file.size
|
const size = file.size
|
||||||
const [mimetype, subtype] = type.split('/')
|
|
||||||
const httpMetadata = { contentType: type, cacheControl }
|
const httpMetadata = { contentType: type, cacheControl }
|
||||||
const filename = getUniqueFilename()
|
const filename = getUniqueFilename()
|
||||||
|
|
||||||
@ -179,7 +178,7 @@ async function saveBlob (
|
|||||||
} else {
|
} else {
|
||||||
await bucket.put(filename, file, { httpMetadata })
|
await bucket.put(filename, file, { httpMetadata })
|
||||||
await sql.begin((sql) => [
|
await sql.begin((sql) => [
|
||||||
db.createData(sql, { hash, location, filename, type: mimetype, subtype, size }),
|
db.createData(sql, { hash, location, filename, type, size }),
|
||||||
db.createBlob(sql, { workspace, name, hash, location })
|
db.createBlob(sql, { workspace, name, hash, location })
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
@ -201,7 +200,7 @@ async function saveBlob (
|
|||||||
} else {
|
} else {
|
||||||
// Otherwise register a new hash and blob
|
// Otherwise register a new hash and blob
|
||||||
await sql.begin((sql) => [
|
await sql.begin((sql) => [
|
||||||
db.createData(sql, { hash, location, filename, type: mimetype, subtype, size }),
|
db.createData(sql, { hash, location, filename, type, size }),
|
||||||
db.createBlob(sql, { workspace, name, hash, location })
|
db.createBlob(sql, { workspace, name, hash, location })
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
@ -227,9 +226,8 @@ export async function handleBlobUploaded (env: Env, workspace: string, name: str
|
|||||||
} else {
|
} else {
|
||||||
const size = object.size
|
const size = object.size
|
||||||
const type = object.httpMetadata.contentType ?? 'application/octet-stream'
|
const type = object.httpMetadata.contentType ?? 'application/octet-stream'
|
||||||
const [mimetype, subtype] = type.split('/')
|
|
||||||
|
|
||||||
await db.createData(sql, { hash, location, filename, type: mimetype, subtype, size })
|
await db.createData(sql, { hash, location, filename, type, size })
|
||||||
await db.createBlob(sql, { workspace, name, hash, location })
|
await db.createBlob(sql, { workspace, name, hash, location })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,6 @@ export interface BlobDataRecord extends BlobDataId {
|
|||||||
filename: UUID
|
filename: UUID
|
||||||
size: number
|
size: number
|
||||||
type: string
|
type: string
|
||||||
subtype: string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BlobId {
|
export interface BlobId {
|
||||||
@ -47,7 +46,7 @@ export async function getData (sql: postgres.Sql, dataId: BlobDataId): Promise<B
|
|||||||
const { hash, location } = dataId
|
const { hash, location } = dataId
|
||||||
|
|
||||||
const rows = await sql<BlobDataRecord[]>`
|
const rows = await sql<BlobDataRecord[]>`
|
||||||
SELECT hash, location, filename, size, type, subtype
|
SELECT hash, location, filename, size, type
|
||||||
FROM blob.data
|
FROM blob.data
|
||||||
WHERE hash = ${hash} AND location = ${location}
|
WHERE hash = ${hash} AND location = ${location}
|
||||||
`
|
`
|
||||||
@ -60,11 +59,11 @@ export async function getData (sql: postgres.Sql, dataId: BlobDataId): Promise<B
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function createData (sql: postgres.Sql, data: BlobDataRecord): Promise<void> {
|
export async function createData (sql: postgres.Sql, data: BlobDataRecord): Promise<void> {
|
||||||
const { hash, location, filename, size, type, subtype } = data
|
const { hash, location, filename, size, type } = data
|
||||||
|
|
||||||
await sql`
|
await sql`
|
||||||
UPSERT INTO blob.data (hash, location, filename, size, type, subtype)
|
UPSERT INTO blob.data (hash, location, filename, size, type)
|
||||||
VALUES (${hash}, ${location}, ${filename}, ${size}, ${type}, ${subtype})
|
VALUES (${hash}, ${location}, ${filename}, ${size}, ${type})
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user