118 lines
3.9 KiB
JavaScript
118 lines
3.9 KiB
JavaScript
import { c as config } from './config-BHx687w1.js';
|
|
import './stores-D9BZZahs.js';
|
|
import './index-k1TR3EJq.js';
|
|
import './index-Ddp2AB5f.js';
|
|
import { s as superValidate, z as zod, f as fail, a as setError } from './zod-BtM9a6Uj.js';
|
|
import { z } from 'zod';
|
|
|
|
const createFormSchema = z.object({
|
|
video_id: z.string()
|
|
// length: z.number().optional(),
|
|
// format: z.enum(["summary", "listicle", "product review", "news report", "tutorial"]).optional(),
|
|
});
|
|
const editFormSchema = z.object({
|
|
id: z.string(),
|
|
title: z.string(),
|
|
content: z.string(),
|
|
is_public: z.boolean()
|
|
});
|
|
|
|
const load = async ({ fetch, url, request }) => {
|
|
const offset = (Number(url.searchParams.get("page") || 1) - 1) * 10;
|
|
const blogRes = await fetch(config.api_url + "/blog?mine=true&offset=" + offset, {
|
|
credentials: "include"
|
|
});
|
|
const videosRes = await fetch(config.api_url + "/videos", {
|
|
credentials: "include"
|
|
});
|
|
const dataBlog = await blogRes.json();
|
|
const dataVideos = await videosRes.json();
|
|
return {
|
|
articles: dataBlog.articles,
|
|
total_articles: dataBlog.total_articles,
|
|
site: dataBlog.site,
|
|
videos: dataVideos.videos,
|
|
createForm: await superValidate(zod(createFormSchema)),
|
|
editForm: await superValidate(zod(editFormSchema))
|
|
};
|
|
};
|
|
const actions = {
|
|
create: async (event) => {
|
|
console.log("creating article...");
|
|
const form = await superValidate(event, zod(createFormSchema));
|
|
if (!form.valid) {
|
|
return fail(400, {
|
|
form
|
|
});
|
|
}
|
|
console.log(form.data);
|
|
const res = await event.fetch(config.api_url + "/dashboard/create", {
|
|
method: "POST",
|
|
body: JSON.stringify(form.data),
|
|
headers: {
|
|
"content-type": "application/json"
|
|
}
|
|
});
|
|
const resData = await res.json();
|
|
if (!resData.success) {
|
|
return setError(form, resData.message);
|
|
}
|
|
return {
|
|
form
|
|
};
|
|
},
|
|
edit: async (event) => {
|
|
const form = await superValidate(event, zod(editFormSchema));
|
|
if (!form.valid) {
|
|
return fail(400, {
|
|
form
|
|
});
|
|
}
|
|
const res = await event.fetch(config.api_url + "/dashboard/article", {
|
|
method: "PUT",
|
|
body: JSON.stringify(form.data),
|
|
headers: {
|
|
"content-type": "application/json"
|
|
}
|
|
});
|
|
const resData = await res.json();
|
|
if (!resData.success) {
|
|
return fail(400, {
|
|
form,
|
|
message: resData.message || ""
|
|
});
|
|
}
|
|
return {
|
|
form
|
|
};
|
|
}
|
|
};
|
|
|
|
var _page_server = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
actions: actions,
|
|
load: load
|
|
});
|
|
|
|
const index = 5;
|
|
let component_cache;
|
|
const component = async () => component_cache ??= (await import('./_page.svelte-BFBOAZM-.js')).default;
|
|
const server_id = "src/routes/(app)/articles/+page.server.js";
|
|
const imports = ["_app/immutable/nodes/5.BKM6xpaP.js","_app/immutable/chunks/scheduler.ncJpckHt.js","_app/immutable/chunks/index.DNKwBhZH.js","_app/immutable/chunks/each.C-Vm-bAH.js","_app/immutable/chunks/table-row.Clc1lodG.js","_app/immutable/chunks/spread.CgU5AtxT.js","_app/immutable/chunks/button.Dry7Ezxz.js","_app/immutable/chunks/index.Bf9t7sah.js","_app/immutable/chunks/index.BHY_2Zs4.js","_app/immutable/chunks/Toaster.svelte_svelte_type_style_lang.C_CyLwr0.js","_app/immutable/chunks/x.IO9lIaqc.js","_app/immutable/chunks/Icon.B73p7tCT.js","_app/immutable/chunks/textarea.XJ9_M7vf.js","_app/immutable/chunks/stores.CwRy5UU2.js","_app/immutable/chunks/entry.LcC2Y6uf.js","_app/immutable/chunks/forms.MoUwlKWk.js","_app/immutable/chunks/config.BSGWJWbh.js"];
|
|
const stylesheets = ["_app/immutable/assets/Toaster.CZzI-Nh6.css","_app/immutable/assets/textarea.Crp_yK76.css"];
|
|
const fonts = [];
|
|
|
|
var _5 = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
component: component,
|
|
fonts: fonts,
|
|
imports: imports,
|
|
index: index,
|
|
server: _page_server,
|
|
server_id: server_id,
|
|
stylesheets: stylesheets
|
|
});
|
|
|
|
export { _5 as _, createFormSchema as c, editFormSchema as e };
|
|
//# sourceMappingURL=5-CIHYdUZq.js.map
|