parsing blog successfully and requesting youtube
This commit is contained in:
35
src/lib/server/content.ts
Normal file
35
src/lib/server/content.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { XMLParser } from 'fast-xml-parser';
|
||||
import { GOOGLE_API_KEY } from '$app/env/private';
|
||||
|
||||
const parser = new XMLParser({
|
||||
ignoreAttributes: false,
|
||||
attributeNamePrefix: '@_',
|
||||
parseAttributeValue: true,
|
||||
trimValues: true
|
||||
});
|
||||
|
||||
async function fetchXml(url: string) {
|
||||
const response = await fetch(url);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch XML: ${response.status}`);
|
||||
}
|
||||
|
||||
const xmlText = await response.text();
|
||||
|
||||
return parser.parse(xmlText);
|
||||
}
|
||||
|
||||
export async function fetchBlogArticles(url: string) {
|
||||
const blogArticles = await fetchXml(url);
|
||||
}
|
||||
|
||||
export async function getChannelInfo(channelId: string) {
|
||||
const response = await fetch(
|
||||
`https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id=${channelId}&key=${GOOGLE_API_KEY}`
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to get Channel Information: ${response.status}`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user