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

121 lines
4.1 KiB
JavaScript
Raw Normal View History

2024-05-29 19:31:10 +00:00
import { c as config } from './config-BHx687w1.js';
2024-06-23 09:25:48 +00:00
import './stores-Cv0rQqhp.js';
import './index-CUXxL1oq.js';
2024-05-29 18:43:41 +00:00
import './index-Ddp2AB5f.js';
2024-06-23 09:25:48 +00:00
import { s as superValidate, z as zod, f as fail, a as setError } from './zod-D1iX83g6.js';
2024-05-29 18:43:41 +00:00
import { z } from 'zod';
const createFormSchema = z.object({
2024-06-10 19:21:30 +00:00
video_id: z.string().regex(/^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/, "Invalid Youtube URL")
2024-05-29 18:43:41 +00:00
// 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()
});
2024-07-21 13:35:30 +00:00
const articlesPerPage = 10;
2024-05-29 18:43:41 +00:00
const load = async ({ fetch, url, request }) => {
2024-07-21 13:35:30 +00:00
const offset = (Number(url.searchParams.get("page") || 1) - 1) * articlesPerPage;
2024-05-29 18:43:41 +00:00
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();
2024-06-21 23:07:29 +00:00
console.log(dataBlog);
2024-05-29 18:43:41 +00:00
return {
articles: dataBlog.articles,
total_articles: dataBlog.total_articles,
2024-06-21 23:07:29 +00:00
article_queue: dataBlog.queue,
2024-05-29 18:43:41 +00:00
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-07-21 15:28:33 +00:00
const component = async () => component_cache ??= (await import('./_page.svelte-DSx8I6bu.js')).default;
2024-05-29 19:16:25 +00:00
const server_id = "src/routes/(app)/articles/+page.server.js";
2024-07-21 15:28:33 +00:00
const imports = ["_app/immutable/nodes/5.CsYTbdBl.js","_app/immutable/chunks/scheduler.Nb9dF4RD.js","_app/immutable/chunks/index.aIvb1r_w.js","_app/immutable/chunks/each.DmwFL-7U.js","_app/immutable/chunks/table-row.CUYNMLiw.js","_app/immutable/chunks/spread.CgU5AtxT.js","_app/immutable/chunks/button.Hx4R_eXH.js","_app/immutable/chunks/index.CnPkSA2E.js","_app/immutable/chunks/index.275uym8j.js","_app/immutable/chunks/Toaster.svelte_svelte_type_style_lang.BVlHgIyE.js","_app/immutable/chunks/x.Dp5nscGL.js","_app/immutable/chunks/Icon.Bv1fUSKH.js","_app/immutable/chunks/textarea.CjmaVwwL.js","_app/immutable/chunks/stores.GzHAC7vm.js","_app/immutable/chunks/entry.BnJdyvtL.js","_app/immutable/chunks/forms.CoP4FF1q.js","_app/immutable/chunks/config.CJ2KPdDA.js"];
2024-06-21 23:07:29 +00:00
const stylesheets = ["_app/immutable/assets/Toaster.CZzI-Nh6.css","_app/immutable/assets/textarea.Crp_yK76.css"];
2024-05-29 18:43:41 +00:00
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-07-21 15:28:33 +00:00
//# sourceMappingURL=5-qIYb_UNQ.js.map