Skip to content

Commit

Permalink
fix twitch stream list/import
Browse files Browse the repository at this point in the history
Fixes #317
  • Loading branch information
saebyn committed Jan 9, 2025
1 parent 581af06 commit 01fdf51
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/ra/dataProvider/restDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ function cleanRecord(resource: string) {
record.id = record.key;
}

if (resource === 'streamIngest') {
record.id = record.executionArn;
}

return record;
};
}
32 changes: 20 additions & 12 deletions src/resources/twitch/List.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ThumbnailField from '@/components/atoms/ThumbnailField';
import ImportIcon from '@mui/icons-material/ImportExport';
import type { Stream } from 'glowing-telegram-types/src/types';
import {
Button,
Datagrid,
Expand Down Expand Up @@ -57,23 +58,26 @@ const BulkActionButtons = () => {
// get the selected records
const selectedRecords = data
.filter((record) => selectedIds.includes(record.id))
.map(({ title, duration, thumbnail_url, stream_id, created_at }) => {
// convert the duration in the format "HHhMMmSSs" to the ISO 8601 format
const durationParts = duration.match(/(\d+)h(\d+)m(\d+)s/);
.map<Omit<Stream, 'id' | 'created_at'>>((record) => {
// convert the duration in the format "HHhMMmSSs"
const durationParts = record.duration.match(/(\d+)h(\d+)m(\d+)s/);

if (!durationParts) {
throw new Error(`Invalid duration format: ${duration}`);
throw new Error(`Invalid duration format: ${record.duration}`);
}

const durationISO = `PT${durationParts[1]}H${durationParts[2]}M${durationParts[3]}S`;
const durationSeconds =
Number.parseInt(durationParts[1], 10) * 3600 +
Number.parseInt(durationParts[2], 10) * 60 +
Number.parseInt(durationParts[3], 10);

const createdAt = new Date(created_at);
const createdAt = new Date(record.created_at);
return {
title,
duration: durationISO,
thumbnail: thumbnail_url,
stream_id,
stream_date: created_at,
title: record.title,
duration: durationSeconds,
thumbnail: record.thumbnail_url,
stream_id: record.stream_id,
stream_date: record.created_at,
stream_platform: 'twitch',

// the date portion of the created_at field
Expand All @@ -83,11 +87,15 @@ const BulkActionButtons = () => {
.getDate()
.toString()
.padStart(2, '0')}`,

description: `Stream from ${record.created_at}`,
has_episodes: false,
video_clip_count: 0,
};
});

// Perform the import
dataProvider.importStreams(selectedRecords).then(() => {
dataProvider.bulkCreate('streams', { data: selectedRecords }).then(() => {
notify('Streams imported');

// Unselect all records
Expand Down

0 comments on commit 01fdf51

Please sign in to comment.