youtuber-blog-frontend/build/server/chunks/5-B_XCs0d_.js

118 lines
3.9 KiB
JavaScript
Raw Normal View History

2024-05-29 19:31:10 +00:00
import { c as config } from './config-BHx687w1.js';
2024-05-29 18:43:41 +00:00
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
});
2024-05-29 19:16:25 +00:00
const index = 5;
2024-05-29 18:43:41 +00:00
let component_cache;
2024-06-07 15:44:08 +00:00
const component = async () => component_cache ??= (await import('./_page.svelte-CSA-RMUS.js')).default;
2024-05-29 19:16:25 +00:00
const server_id = "src/routes/(app)/articles/+page.server.js";
2024-06-07 15:44:08 +00:00
const imports = ["_app/immutable/nodes/5.CmHdTPxN.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.NKPApmbs.js","_app/immutable/chunks/stores.C4GgOdjS.js","_app/immutable/chunks/entry.DWCTrrqg.js","_app/immutable/chunks/forms.iMCVO3UF.js","_app/immutable/chunks/config.gX2_MlFr.js"];
2024-05-29 18:43:41 +00:00
const stylesheets = ["_app/immutable/assets/Toaster.CZzI-Nh6.css","_app/immutable/assets/textarea.Crp_yK76.css"];
const fonts = [];
2024-05-29 19:16:25 +00:00
var _5 = /*#__PURE__*/Object.freeze({
2024-05-29 18:43:41 +00:00
__proto__: null,
component: component,
fonts: fonts,
imports: imports,
index: index,
server: _page_server,
server_id: server_id,
stylesheets: stylesheets
});
2024-05-29 19:16:25 +00:00
export { _5 as _, createFormSchema as c, editFormSchema as e };
2024-06-07 15:44:08 +00:00
//# sourceMappingURL=5-B_XCs0d_.js.map