import { c as config } from './config-DeQcbWtq.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 = 6; let component_cache; const component = async () => component_cache ??= (await import('./_page.svelte-BKqAx15f.js')).default; const server_id = "src/routes/app/(app)/articles/+page.server.js"; const imports = ["_app/immutable/nodes/6.H-Hl4ySa.js","_app/immutable/chunks/scheduler.lbjRT0Rl.js","_app/immutable/chunks/index.CaCtjzNU.js","_app/immutable/chunks/each.DOzsyxQl.js","_app/immutable/chunks/table-row.x0N_Rq8P.js","_app/immutable/chunks/spread.CgU5AtxT.js","_app/immutable/chunks/button.DX8b0Nu3.js","_app/immutable/chunks/index.B3mWxGlt.js","_app/immutable/chunks/index.DJbdiDqX.js","_app/immutable/chunks/Toaster.svelte_svelte_type_style_lang.C2CX7RdJ.js","_app/immutable/chunks/x.BTxbVvtW.js","_app/immutable/chunks/Icon.BJIkZJEf.js","_app/immutable/chunks/textarea.ZKumXjmr.js","_app/immutable/chunks/stores.pmcZ7n9I.js","_app/immutable/chunks/entry.D3NuBkEq.js","_app/immutable/chunks/forms.B4Lu25yK.js","_app/immutable/chunks/_commonjsHelpers.IkB594pC.js"]; const stylesheets = ["_app/immutable/assets/Toaster.CZzI-Nh6.css","_app/immutable/assets/textarea.Crp_yK76.css"]; const fonts = []; var _6 = /*#__PURE__*/Object.freeze({ __proto__: null, component: component, fonts: fonts, imports: imports, index: index, server: _page_server, server_id: server_id, stylesheets: stylesheets }); export { _6 as _, createFormSchema as c, editFormSchema as e }; //# sourceMappingURL=6-BkwwCheY.js.map