Add plugin media
This commit is contained in:
@@ -4,17 +4,17 @@ import type {
|
||||
MediaPage,
|
||||
} from "@reacteditor/plugin-media";
|
||||
|
||||
const MEDIA_BASE = "https://www.frontend-ai.com";
|
||||
const MEDIA_API_KEY = process.env.NEXT_PUBLIC_API_KEY ?? "";
|
||||
const FRONTEND_CLOUD = "https://cloud.frontend.co";
|
||||
const FRONTEND_API_KEY = process.env.NEXT_PUBLIC_FRONTEND_API_KEY ?? "";
|
||||
|
||||
export const frontendAiMediaAdapter: MediaAdapter = {
|
||||
fetchList: async ({ query, cursor, signal }) => {
|
||||
const url = new URL("/api/media", MEDIA_BASE);
|
||||
const url = new URL("/api/media", FRONTEND_CLOUD);
|
||||
if (query) url.searchParams.set("query", query);
|
||||
if (cursor) url.searchParams.set("cursor", cursor);
|
||||
const res = await fetch(url, {
|
||||
method: "GET",
|
||||
headers: { "X-Api-Key": MEDIA_API_KEY },
|
||||
headers: { "X-Api-Key": FRONTEND_API_KEY },
|
||||
signal,
|
||||
});
|
||||
if (!res.ok) throw new Error(`List failed: ${res.status}`);
|
||||
@@ -24,8 +24,8 @@ export const frontendAiMediaAdapter: MediaAdapter = {
|
||||
upload: (file, opts) =>
|
||||
new Promise<MediaItem>((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", `${MEDIA_BASE}/api/media`);
|
||||
xhr.setRequestHeader("X-Api-Key", MEDIA_API_KEY);
|
||||
xhr.open("POST", `${FRONTEND_CLOUD}/api/media`);
|
||||
xhr.setRequestHeader("X-Api-Key", FRONTEND_API_KEY);
|
||||
xhr.upload.onprogress = (e) => {
|
||||
if (e.lengthComputable) opts?.onProgress?.(e.loaded / e.total);
|
||||
};
|
||||
@@ -54,10 +54,10 @@ export const frontendAiMediaAdapter: MediaAdapter = {
|
||||
|
||||
delete: async (id) => {
|
||||
const res = await fetch(
|
||||
`${MEDIA_BASE}/api/media/${encodeURIComponent(id)}`,
|
||||
`${FRONTEND_CLOUD}/api/media/${encodeURIComponent(id)}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
headers: { "X-Api-Key": MEDIA_API_KEY },
|
||||
headers: { "X-Api-Key": FRONTEND_API_KEY },
|
||||
},
|
||||
);
|
||||
if (!res.ok) throw new Error(`Delete failed: ${res.status}`);
|
||||
|
||||
Reference in New Issue
Block a user