feat(watchlist): yaml helpers + schema types
This commit is contained in:
parent
e7714736ce
commit
cade7104db
3 changed files with 118 additions and 0 deletions
40
packages/obsidian/src/watchlist/schema.ts
Normal file
40
packages/obsidian/src/watchlist/schema.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
export type WatchCategory = 'Movie' | 'Series' | 'Anime';
|
||||
export type WatchMediaType = 'Movie' | 'TV Series';
|
||||
|
||||
export interface WatchlistRecord {
|
||||
title: string;
|
||||
engName: string;
|
||||
mediaType: WatchMediaType;
|
||||
category: WatchCategory;
|
||||
watchStatus: string;
|
||||
rating: string;
|
||||
ratingStars: string;
|
||||
year: string;
|
||||
runtime: number | null;
|
||||
seasons: number | null;
|
||||
episodes: number | null;
|
||||
vod: string[];
|
||||
genre: string[];
|
||||
status: string;
|
||||
language: string;
|
||||
country: string;
|
||||
director: string[];
|
||||
writer: string[];
|
||||
producer: string[];
|
||||
contentRating: string;
|
||||
tmdbRating: number | null;
|
||||
tmdbId: string;
|
||||
imdbId: string;
|
||||
releaseDate: string | null;
|
||||
lastAirDate: string | null;
|
||||
nextAirDate: string | null;
|
||||
lastEpisode: string | null;
|
||||
upcomingEpisode: string | null;
|
||||
poster: string | null;
|
||||
trailer: string;
|
||||
homepage: string;
|
||||
imdbPage: string;
|
||||
notionUrl: string;
|
||||
synopsis: string;
|
||||
cast: string;
|
||||
}
|
||||
25
packages/obsidian/src/watchlist/yaml.ts
Normal file
25
packages/obsidian/src/watchlist/yaml.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
const NEEDS_QUOTE = /[:,#\[\]{}"&*!|>%@`]/;
|
||||
const KEYWORDS = new Set(['null', 'true', 'false', 'yes', 'no']);
|
||||
|
||||
export function yamlScalar(v: unknown): string {
|
||||
if (v === null || v === undefined || v === '') return '';
|
||||
const s = String(v);
|
||||
if (NEEDS_QUOTE.test(s) || s.trim() !== s || KEYWORDS.has(s.toLowerCase())) {
|
||||
return '"' + s.replace(/"/g, '\\"') + '"';
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
export function yamlList(items: string[]): string {
|
||||
const parts: string[] = [];
|
||||
for (const raw of items) {
|
||||
const g = String(raw).trim();
|
||||
if (!g) continue;
|
||||
parts.push(/^[A-Za-z0-9 ]+$/.test(g) ? g : '"' + g.replace(/"/g, '\\"') + '"');
|
||||
}
|
||||
return '[' + parts.join(', ') + ']';
|
||||
}
|
||||
|
||||
export function quotedOrNull(v: string | null | undefined): string {
|
||||
return v ? '"' + v + '"' : 'null';
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue