import { c as config } from './config-BHx687w1.js'; import './stores-q_3MsRzq.js'; import './index-DFEd82Gl.js'; import './index-Ddp2AB5f.js'; import { s as superValidate, z as zod, f as fail, a as setError } from './zod-B9q4bgLb.js'; import { z } from 'zod'; const createFormSchema = z.object({ video_id: z.string().regex(/^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/, "Invalid Youtube URL") // 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(); console.log(dataBlog); return { articles: dataBlog.articles, total_articles: dataBlog.total_articles, article_queue: dataBlog.queue, 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-2THqD6gv.js')).default; const server_id = "src/routes/(app)/articles/+page.server.js"; const imports = ["_app/immutable/nodes/5.CI7lPaRK.js","_app/immutable/chunks/scheduler.BsMbz5U8.js","_app/immutable/chunks/index.rkWRBFIu.js","_app/immutable/chunks/each.jOEBnCSj.js","_app/immutable/chunks/table-row.CXdrGY0F.js","_app/immutable/chunks/spread.CgU5AtxT.js","_app/immutable/chunks/button.Ba55pzkL.js","_app/immutable/chunks/index.BBc34iid.js","_app/immutable/chunks/index.DwF-TCr7.js","_app/immutable/chunks/Toaster.svelte_svelte_type_style_lang.DiP1zXXX.js","_app/immutable/chunks/x.BhzcNrGh.js","_app/immutable/chunks/textarea.OR1yZTo2.js","_app/immutable/chunks/stores.Dq-jxEEw.js","_app/immutable/chunks/entry.iekzDyP5.js","_app/immutable/chunks/forms.CYRa2lUv.js","_app/immutable/chunks/config.CaMjilIn.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-CJoPpcou.js.map