Skip to content

Commit

Permalink
Start implementing asset data
Browse files Browse the repository at this point in the history
  • Loading branch information
xremming committed Mar 28, 2021
1 parent 6e0ccb6 commit a423487
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
22 changes: 22 additions & 0 deletions pages/api/v1/asset/data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { NextApiRequest, NextApiResponse } from "next";

export default async function (req: NextApiRequest, res: NextApiResponse) {
const allow = "OPTIONS, GET";

try {
switch (req.method) {
case "OPTIONS":
res.setHeader("Allow", allow);
return res.status(204).end();

case "GET":
return res.json({ data: await get(req.query) });

default:
res.setHeader("Allow", allow);
return res.status(405).end();
}
} catch (error) {
res.status(500).end();
}
}
File renamed without changes.
7 changes: 6 additions & 1 deletion src/service/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
import { formatRFC7231 } from "date-fns";
import { NextApiResponse } from "next";
import { Readable } from "stream";
import { GetAssetHeaders, GetAssetQuery } from "type/api";
import { GetAssetData, GetAssetHeaders, GetAssetQuery } from "type/api";
import { AssetDatas } from "type/asset";

function constructHeaders(
res: HeadObjectCommandOutput | GetObjectCommandOutput
Expand Down Expand Up @@ -129,3 +130,7 @@ export async function getAsset(
body: data.Body as Readable,
});
}

export async function getAssetData(query: GetAssetData): Promise<AssetDatas> {
return [];
}
10 changes: 10 additions & 0 deletions src/type/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ export const GetAssetHeaders = t.object({
});
export type GetAssetHeaders = t.infer<typeof GetAssetHeaders>;

export const GetAssetData = t.object({
spaceId: t.string().uuid(),
assetId: t.union([
t.undefined(),
t.string().uuid(),
t.array(t.string().uuid()),
]),
});
export type GetAssetData = t.infer<typeof GetAssetData>;

// ITEM

export const GetItemsQuery = t.object({
Expand Down
17 changes: 17 additions & 0 deletions src/type/asset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as t from "zod";

export const Kind = t.enum(["image", "video", "audio", "pdf", "other"]);
export type Kind = t.infer<typeof Kind>;

export const AssetData = t.object({
spaceId: t.string().uuid(),
assetId: t.string().uuid(),
size: t.number().int(),
contentType: t.string(),
filename: t.string(),
kind: Kind,
});
export type AssetData = t.infer<typeof AssetData>;

export const AssetDatas = t.array(AssetData);
export type AssetDatas = t.infer<typeof AssetDatas>;

0 comments on commit a423487

Please sign in to comment.