update
parent
94d2479dc9
commit
620ae4d444
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,200 @@
|
||||
import * as React from "react";
|
||||
import {
|
||||
Admin,
|
||||
Resource,
|
||||
List,
|
||||
Datagrid,
|
||||
NumberField,
|
||||
TextField,
|
||||
DateField,
|
||||
RichTextField,
|
||||
UrlField,
|
||||
ReferenceField,
|
||||
FileField,
|
||||
Show,
|
||||
Edit,
|
||||
Create,
|
||||
SimpleForm,
|
||||
TextInput,
|
||||
NumberInput,
|
||||
DateTimeInput,
|
||||
RadioButtonGroupInput,
|
||||
SelectInput,
|
||||
|
||||
SimpleShowLayout,
|
||||
|
||||
useGetList
|
||||
} from 'react-admin';
|
||||
import { RichTextInput } from 'ra-input-rich-text';
|
||||
import simpleRestProvider from 'ra-data-simple-rest';
|
||||
|
||||
import { API_ADMIN_ROOT } from '@/paths';
|
||||
|
||||
export const UserList = () => (
|
||||
<List>
|
||||
<Datagrid>
|
||||
<TextField source="id" />
|
||||
<TextField source="email" />
|
||||
</Datagrid>
|
||||
</List>
|
||||
);
|
||||
|
||||
export const SubscriptionList = () => (
|
||||
<List>
|
||||
<Datagrid>
|
||||
<TextField source="id" />
|
||||
<TextField source="uuid" />
|
||||
<ReferenceField source="user_id" reference="users" label="Email" link="show">
|
||||
<TextField source="email" />
|
||||
</ReferenceField>
|
||||
<DateField source="started_date" />
|
||||
</Datagrid>
|
||||
</List>
|
||||
)
|
||||
|
||||
export const EpisodesList = () => (
|
||||
<List>
|
||||
<Datagrid rowClick="show">
|
||||
<TextField source="id" />
|
||||
<NumberField source="number" />
|
||||
<TextField source="title" />
|
||||
<NumberField source="episode" />
|
||||
<TextField source="slug" />
|
||||
<TextField source="episode_type" />
|
||||
<TextField source="buzzsprout_id" />
|
||||
<DateField source="pub_date" showTime={true} />
|
||||
</Datagrid>
|
||||
</List>
|
||||
);
|
||||
|
||||
export const AudioFilesList = () => (
|
||||
<List>
|
||||
<Datagrid>
|
||||
<TextField source="id" />
|
||||
<FileField source="filename" title="filename" />
|
||||
</Datagrid>
|
||||
</List>
|
||||
);
|
||||
|
||||
export const EpisodeShow = (props) => (
|
||||
<Show {...props}>
|
||||
<SimpleShowLayout>
|
||||
<TextField source="id" />
|
||||
<NumberField source="number" />
|
||||
<TextField source="title" />
|
||||
<NumberField source="season" />
|
||||
<NumberField source="episode" />
|
||||
<NumberField source="duration" />
|
||||
<TextField source="slug" />
|
||||
<TextField source="episode_type" />
|
||||
<TextField source="buzzsprout_id" />
|
||||
<UrlField source="buzzsprout_url" />
|
||||
<UrlField source="youtube_url" />
|
||||
<UrlField source="audio_url" />
|
||||
<FileField source="transcript_filename" title="transcript_filename" />
|
||||
<DateField source="pub_date" showTime={true} />
|
||||
<RichTextField source="content" />
|
||||
<TextField source="summary" />
|
||||
</SimpleShowLayout>
|
||||
</Show>
|
||||
);
|
||||
|
||||
export const EpisodeEdit = () => {
|
||||
return (
|
||||
<Edit>
|
||||
<SimpleForm>
|
||||
<TextInput source="number" />
|
||||
<TextInput source="title" />
|
||||
<NumberInput source="season" />
|
||||
<NumberInput source="episode" />
|
||||
<TextInput source="slug" />
|
||||
<TextInput source="episode_type" />
|
||||
<TextInput source="buzzsprout_id" />
|
||||
<TextInput source="buzzsprout_url" />
|
||||
<TextInput source="youtube_url" />
|
||||
<TextInput source="audio_url" />
|
||||
<TextInput source="transcript_filename" />
|
||||
<DateTimeInput source="pub_date" />
|
||||
<RichTextInput source="content" />
|
||||
<TextInput source="summary" />
|
||||
</SimpleForm>
|
||||
</Edit>
|
||||
);
|
||||
};
|
||||
|
||||
function listElement(arr, proc) {
|
||||
return arr && arr.length > 0 ? proc(arr[0]) : undefined;
|
||||
};
|
||||
|
||||
export const EpisodeCreate = () => {
|
||||
const { data: lastNumber } = useGetList(
|
||||
'episodes',
|
||||
{
|
||||
pagination: { page: 1, perPage: 2 },
|
||||
sort: { field: 'number', order: 'DESC' }
|
||||
}
|
||||
);
|
||||
const { data: lastEpisode } = useGetList(
|
||||
'episodes',
|
||||
{
|
||||
pagination: { page: 1, perPage: 2 },
|
||||
sort: { field: 'episode', order: 'DESC' }
|
||||
}
|
||||
);
|
||||
const { data: transcriptFiles } = useGetList(
|
||||
'transcript_files'
|
||||
);
|
||||
if (lastNumber && lastEpisode && audioFiles && transcriptFiles) {
|
||||
return (
|
||||
<Create>
|
||||
<SimpleForm>
|
||||
<TextInput source="number" defaultValue={listElement(lastNumber, x => x.number + 1)} />
|
||||
<TextInput source="title" fullWidth />
|
||||
<NumberInput source="season" defaultValue="1" />
|
||||
<NumberInput source="episode" defaultValue={listElement(lastEpisode, x => x.episode + 1)} />
|
||||
<TextInput source="slug" fullWidth />
|
||||
<RadioButtonGroupInput
|
||||
source="episode_type"
|
||||
choices={[
|
||||
{ id: 'full', name: 'full' },
|
||||
{ id: 'bonus', name: 'bonus' }
|
||||
]}
|
||||
defaultValue="full"
|
||||
/>
|
||||
<TextInput
|
||||
source="buzzsprout_id"
|
||||
label="Buzzsprout ID"
|
||||
format={v => v && v.split('-').length > 0 ? v.split('-')[1] : ''}
|
||||
parse={v => `Buzzsprout-${v}`}
|
||||
defaultValue=""
|
||||
/>
|
||||
<TextInput source="buzzsprout_url" fullWidth />
|
||||
<TextInput source="youtube_url" fullWidth />
|
||||
<TextInput source="audio_url" fullWidth />
|
||||
<SelectInput
|
||||
source="transcript_filename"
|
||||
choices={transcriptFiles.map(x => { return { id: x.filename, name: x.filename } })}
|
||||
/>
|
||||
<DateTimeInput source="pub_date" />
|
||||
<RichTextInput source="content" />
|
||||
<TextInput source="summary" fullWidth />
|
||||
</SimpleForm>
|
||||
</Create>
|
||||
);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const App = () => (
|
||||
<Admin dataProvider={simpleRestProvider(API_ADMIN_ROOT)}>
|
||||
<Resource name="users" list={UserList} />
|
||||
<Resource name="subscriptions" list={SubscriptionList} />
|
||||
<Resource name="episodes" list={EpisodesList} show={EpisodeShow} edit={EpisodeEdit} create={EpisodeCreate} />
|
||||
<Resource name="audio_files" list={AudioFilesList} />
|
||||
<Resource name="transcript_files" list={AudioFilesList} />
|
||||
</Admin>
|
||||
);
|
||||
|
||||
export default App;
|
@ -0,0 +1,8 @@
|
||||
import dynamic from "next/dynamic"
|
||||
const App = dynamic(() => import("@/admin/App"), { ssr: false })
|
||||
|
||||
const AdminPage = () => {
|
||||
return <App />;
|
||||
};
|
||||
|
||||
export default AdminPage;
|
@ -0,0 +1,14 @@
|
||||
const fs = require('fs');
|
||||
|
||||
export default async function handler(req, res) {
|
||||
if (req.method === 'GET') {
|
||||
const files = fs.readdirSync('./public/files/episodes', {withFileTypes: true})
|
||||
.filter(item => !item.isDirectory())
|
||||
.map(item => item.name);
|
||||
files.sort();
|
||||
files.reverse();
|
||||
|
||||
res.setHeader('Content-Range', files.length);
|
||||
res.status(200).json(files.map((f, i) => { return { id: i, filename: f } }));
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
import db from '@/db';
|
||||
|
||||
const COLS = {};
|
||||
const COLS_PREFIXED = {};
|
||||
const COLS_LIST = ['id', 'number', 'content', 'summary', 'slug', 'season', 'episode', 'duration', 'filename', 'title', 'episode_type', 'buzzsprout_id', 'buzzsprout_url', 'pub_date', 'youtube_url', 'transcript_filename', 'audio_url'];
|
||||
COLS_LIST.forEach((k) => COLS[k] = k)
|
||||
COLS_LIST.forEach((k) => COLS_PREFIXED[k] = `$${k}`)
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const sessionId = req.cookies?.session;
|
||||
if (!sessionId) { res.status(404).json({}); return; }
|
||||
const sessionRes = await db.get('select email from sessions join users on users.id = sessions.user_id where session_id=?;', sessionId);
|
||||
if (!sessionRes || sessionRes?.email != process.env.ADMIN_EMAIL) { res.status(404).json({}); return; }
|
||||
const { id } = req.query;
|
||||
if (req.method === 'GET') {
|
||||
const episode = await db.get('select * from episodes where id = ?', id);
|
||||
res.status(200).json(episode)
|
||||
} else if (req.method === 'PUT') {
|
||||
const changes = req.body;
|
||||
const changesForSQL = {};
|
||||
Object.keys(changes).forEach((k) => changesForSQL[COLS_PREFIXED[k]] = changes[k]);
|
||||
const { id } = await db.get(`update episodes set ${Object.keys(changes).map((k) => `${COLS[k]} = ${COLS_PREFIXED[k]}`).join(', ')} where id = $id returning id;`, changesForSQL);
|
||||
const episode = await db.get('select * from episodes where id = ?', id);
|
||||
res.status(200).json(episode)
|
||||
} else if (req.method = 'DELETE') {
|
||||
const episode = await db.get('select * from episodes where id = ?', id);
|
||||
await db.run('delete from episodes where id = ?', id);
|
||||
res.status(200).json(episode);
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
import db from '@/db';
|
||||
|
||||
const SORT_MAP = {
|
||||
'ASC': 'asc',
|
||||
'DESC': 'desc'
|
||||
};
|
||||
|
||||
const COLUMN_MAP = {
|
||||
'id': 'id',
|
||||
'number': 'number',
|
||||
'episode': 'episode'
|
||||
};
|
||||
|
||||
const COLS_LIST = ['number', 'content', 'summary', 'slug', 'season', 'episode', 'duration', 'filename', 'title', 'episode_type', 'buzzsprout_id', 'buzzsprout_url', 'pub_date', 'youtube_url', 'transcript_filename', 'audio_url'];
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const sessionId = req.cookies?.session;
|
||||
if (!sessionId) { res.status(404).json({}); return; }
|
||||
const sessionRes = await db.get('select email from sessions join users on users.id = sessions.user_id where session_id=?;', sessionId);
|
||||
if (!sessionRes || sessionRes?.email != process.env.ADMIN_EMAIL) { res.status(404).json({}); return; }
|
||||
if (req.method === 'GET') {
|
||||
const { sort, range, filter } = req.query;
|
||||
const [sortColumn, sortDirection] = sort ? JSON.parse(sort) : [false, false];
|
||||
const [rangeStart, rangeEnd] = range ? JSON.parse(range) : [false, false];
|
||||
let rows;
|
||||
if (sort && range) {
|
||||
rows = await db.all(`select * from episodes order by ${COLUMN_MAP[sortColumn]} ${SORT_MAP[JSON.parse(sort)[1]]} limit ? offset ?;`, rangeEnd - rangeStart, rangeStart);
|
||||
} else if (filter) {
|
||||
const filterParsed = JSON.parse(filter);
|
||||
rows = await db.all(`select * from episodes where id in (${filterParsed['id'].map(x => '?').join(',')})`, filterParsed['id']);
|
||||
}
|
||||
const { count } = await db.get('select count(id) as count from episodes;');
|
||||
|
||||
res.setHeader('Content-Range', count);
|
||||
res.status(200).json(rows)
|
||||
} else if (req.method === 'POST') {
|
||||
await db.run(`insert into episodes (${COLS_LIST.join(', ')}) values (${COLS_LIST.map(() => '?').join(', ')});`,
|
||||
COLS_LIST.map((c) => req.body[c]));
|
||||
const episode = await db.get('select * from episodes where number = ? and title = ? and slug = ?', req.body['number'], req.body['title'], req.body['slug']);
|
||||
res.status(200).json(episode);
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
import db from '@/db';
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const sessionId = req.cookies?.session;
|
||||
if (!sessionId) { res.status(404).json({}); return; }
|
||||
const sessionRes = await db.get('select email from sessions join users on users.id = sessions.user_id where session_id=?;', sessionId);
|
||||
if (!sessionRes || sessionRes?.email != process.env.ADMIN_EMAIL) { res.status(404).json({}); return; }
|
||||
if (req.method === 'GET') {
|
||||
const rows = await db.all('select id, user_id, uuid, started_date from subscriptions;');
|
||||
|
||||
res.setHeader('Content-Range', rows.length);
|
||||
res.status(200).json(rows)
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
const fs = require('fs');
|
||||
|
||||
export default async function handler(req, res) {
|
||||
if (req.method === 'GET') {
|
||||
const filesOrig = fs.readdirSync('./src/data', {withFileTypes: true})
|
||||
.filter(item => !item.isDirectory())
|
||||
.map(item => item.name);
|
||||
const files = filesOrig.filter(f => f.includes('.srt'));
|
||||
files.sort();
|
||||
files.reverse();
|
||||
|
||||
res.setHeader('Content-Range', files.length);
|
||||
res.status(200).json(files.map((f, i) => { return { id: i, filename: f } }));
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
|
||||
|
||||
import db from '@/db';
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const sessionId = req.cookies?.session;
|
||||
if (!sessionId) { res.status(404).json({}); return; }
|
||||
const sessionRes = await db.get('select email from sessions join users on users.id = sessions.user_id where session_id=?;', sessionId);
|
||||
if (!sessionRes || sessionRes?.email != process.env.ADMIN_EMAIL) { res.status(404).json({}); return; }
|
||||
if (req.method === 'GET') {
|
||||
const rows = await db.all('select id, email from users;');
|
||||
|
||||
res.setHeader('Content-Range', rows.length);
|
||||
res.status(200).json(rows)
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
// export const ROOT = 'https://www.thereactshow.com';
|
||||
export const ROOT = process.env.SITE_ROOT;
|
||||
export const FEED_ROOT = `${ROOT}/api/feed`;
|
||||
export const REACTORS = `${ROOT}/reactors`;
|
||||
export const REACTORS_ACCOUNT = `${REACTORS}/account`;
|
||||
export const PODCAST_PAGE_ROOT = `${ROOT}/podcast`;
|
||||
export const EPISODE_FILE_ROOT = `${ROOT}/files/episodes`;
|
||||
export const API_ROOT = '/api';
|
||||
export const API_ADMIN_ROOT = `${API_ROOT}/admin`;
|
||||
export const API_USERS = `${API_ADMIN_ROOT}/users`;
|
||||
|
||||
export const accountFeedURL = (uuid) => `${FEED_ROOT}/${uuid}.rss`;
|
||||
export const accountUnsubscribeURL = (uuid) => `${REACTORS_ACCOUNT}/${uuid}/unsubscribe`;
|
||||
|
||||
export const podcastPage = (slug) => `${PODCAST_PAGE_ROOT}/${slug}`;
|
||||
export const episodeFile = (filename) => `${EPISODE_FILE_ROOT}/${filename}`;
|
Loading…
Reference in New Issue