chore(config): centralize feature settings
This commit is contained in:
@@ -13,6 +13,11 @@ import {
|
||||
type VideoPublishJobRecord,
|
||||
type VideoPublishUploadRecord,
|
||||
} from "@/lib/video/video-publishing";
|
||||
import {
|
||||
getTiktokApiConfig,
|
||||
getYoutubeFollowerConfig,
|
||||
getYoutubePublishingConfig,
|
||||
} from "@/lib/config/server";
|
||||
|
||||
const VIDEO_TYPES = new Set(["video/mp4", "video/quicktime", "video/webm"]);
|
||||
|
||||
@@ -39,9 +44,13 @@ export function validateThumbnailFile(file: File) {
|
||||
}
|
||||
|
||||
export async function getLatestYoutubeVideos(): Promise<LatestVideo[]> {
|
||||
const apiKey = process.env.YOUTUBE_API_KEY;
|
||||
const channelId = process.env.YOUTUBE_CHANNEL_ID;
|
||||
if (!apiKey || !channelId) return [];
|
||||
let apiKey: string;
|
||||
let channelId: string;
|
||||
try {
|
||||
({ apiKey, channelId } = getYoutubeFollowerConfig());
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
const channels = await fetch(
|
||||
`https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id=${encodeURIComponent(channelId)}&key=${encodeURIComponent(apiKey)}`,
|
||||
{ cache: "no-store" },
|
||||
@@ -90,11 +99,15 @@ export async function getLatestYoutubeVideos(): Promise<LatestVideo[]> {
|
||||
}
|
||||
|
||||
async function getTiktokAccessToken() {
|
||||
const refreshToken = process.env.TIKTOK_REFRESH_TOKEN;
|
||||
const clientKey = process.env.TIKTOK_CLIENT_KEY;
|
||||
const clientSecret = process.env.TIKTOK_CLIENT_SECRET;
|
||||
if (!refreshToken || !clientKey || !clientSecret)
|
||||
return process.env.TIKTOK_ACCESS_TOKEN ?? null;
|
||||
let config: ReturnType<typeof getTiktokApiConfig>;
|
||||
try {
|
||||
config = getTiktokApiConfig();
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
if (config.accessToken) return config.accessToken;
|
||||
const { refreshToken, clientKey, clientSecret } = config;
|
||||
if (!refreshToken || !clientKey || !clientSecret) return null;
|
||||
const response = await fetch("https://open.tiktokapis.com/v2/oauth/token/", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
||||
@@ -151,11 +164,7 @@ export async function getLatestTiktokVideos(): Promise<LatestVideo[]> {
|
||||
}
|
||||
|
||||
async function youtubeAccessToken() {
|
||||
const refreshToken = process.env.YOUTUBE_REFRESH_TOKEN;
|
||||
const clientId = process.env.YOUTUBE_CLIENT_ID;
|
||||
const clientSecret = process.env.YOUTUBE_CLIENT_SECRET;
|
||||
if (!refreshToken || !clientId || !clientSecret)
|
||||
throw new Error("YouTube OAuth is not configured.");
|
||||
const { refreshToken, clientId, clientSecret } = getYoutubePublishingConfig();
|
||||
const response = await fetch("https://oauth2.googleapis.com/token", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
||||
|
||||
Reference in New Issue
Block a user