-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is still totally WIP, but landing it sooner than later for very early live testing. This page shows a feed and its episodes. It also lets you edit episodes and the feeds and create a new feed.
- Loading branch information
Showing
34 changed files
with
986 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import SQL from '@nearform/sql' | ||
|
||
export function getEpisodesQuery ({ | ||
ownerId, | ||
episodeId, | ||
before, | ||
sensitive, | ||
perPage, | ||
feedId | ||
}) { | ||
const episodesQuery = SQL` | ||
select | ||
ep.id, | ||
ep.podcast_feed_id, | ||
ep.created_at, | ||
ep.updated_at, | ||
ep.url, | ||
ep.type, | ||
ep.medium, | ||
ep.size_in_bytes, | ||
ep.duration_in_seconds, | ||
ep.mime_type, | ||
ep.explicit, | ||
ep.author_name, | ||
ep.filename, | ||
ep.ext, | ||
ep.src_type, | ||
ep.ready, | ||
ep.error, | ||
jsonb_build_object( | ||
'id', bm.id, | ||
'url', bm.url, | ||
'title', bm.title, | ||
'note', bm.note, | ||
'created_at', bm.created_at, | ||
'updated_at', bm.updated_at, | ||
'starred', bm.starred, | ||
'toread', bm.toread, | ||
'sensitive', bm.sensitive | ||
) as bookmark | ||
from episodes ep | ||
join bookmarks bm | ||
on ep.bookmark_id = bm.id | ||
where ep.owner_id = ${ownerId} | ||
and bm.owner_id = ${ownerId} | ||
${feedId ? SQL`and ep.podcast_feed_id = ${feedId}` : SQL``} | ||
${episodeId ? SQL`and ep.id = ${episodeId}` : SQL``} | ||
${before ? SQL`and ep.created_at < ${before}` : SQL``} | ||
${!sensitive ? SQL`and sensitive = false` : SQL``} | ||
order by ep.created_at desc, ep.url desc, bm.title desc | ||
${perPage != null ? SQL`fetch first ${perPage} rows only` : SQL``} | ||
` | ||
|
||
return episodesQuery | ||
} | ||
|
||
export function afterToBeforeEpisodesQuery ({ | ||
perPage, | ||
ownerId, | ||
after, | ||
sensitive, | ||
feedId | ||
}) { | ||
const perPageAfterOffset = perPage + 2 | ||
|
||
const afterCalcEpisodesQuery = SQL` | ||
with page as ( | ||
select ep.id, ep.created_at | ||
from episodes ep | ||
${!sensitive | ||
? SQL` | ||
join bookmarks bm | ||
on ep.bookmark_id = bm.id` | ||
: SQL``} | ||
where ep.owner_id = ${ownerId} | ||
and ep.created_at >= ${after} | ||
${feedId ? SQL`and ep.podcast_feed_id = ${feedId}` : SQL``} | ||
${!sensitive | ||
? SQL` | ||
and bm.owner_id = ${ownerId} | ||
and bm.sensitive = false | ||
` | ||
: SQL`` | ||
} | ||
order by ep.created_at ASC, ep.url ASC | ||
fetch first ${perPageAfterOffset} rows only | ||
), | ||
episode_with_last_row_date as ( | ||
select last_value(page.created_at) over ( | ||
order by page.created_at | ||
range between | ||
UNBOUNDED PRECEDING AND | ||
UNBOUNDED FOLLOWING | ||
) last_created_at | ||
from page | ||
) | ||
select count(*)::int as episode_count, last_created_at | ||
from episode_with_last_row_date | ||
group by last_created_at | ||
` | ||
|
||
return afterCalcEpisodesQuery | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* eslint-disable camelcase */ | ||
import { fullFeedProps } from '../../feed-props.js' | ||
import { getFeedQuery } from '../get-feed-query.js' | ||
import { getFeedUrl } from '../../get-feed-url.js' | ||
|
||
export default async function getFeedDetails (fastify, opts) { | ||
fastify.get( | ||
'/', | ||
{ | ||
preHandler: fastify.auth([fastify.verifyJWT]), | ||
schema: { | ||
parms: { | ||
type: 'object', | ||
properties: { | ||
feed: { | ||
type: 'string', | ||
format: 'uuid' | ||
} | ||
}, | ||
required: ['feed'] | ||
}, | ||
response: { | ||
200: { | ||
type: 'object', | ||
properties: { | ||
data: { | ||
type: 'array', | ||
items: { | ||
type: 'object', | ||
properties: { | ||
...fullFeedProps | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
|
||
async function getFeedHandler (request, reply) { | ||
const userId = request.user.id | ||
const { feed: feedId } = request.params | ||
|
||
const query = getFeedQuery({ | ||
ownerId: userId, | ||
feedId, | ||
perPage: 1 | ||
}) | ||
|
||
const results = await fastify.pg.query(query) | ||
const feed = results.rows[0] | ||
if (!feed) { | ||
return reply.notFound('feed not found') | ||
} | ||
return { | ||
...feed, | ||
feed_url: getFeedUrl({ | ||
transport: fastify.config.TRANSPORT, | ||
host: fastify.config.HOST, | ||
userId, | ||
token: feed.token, | ||
feedId: feed.id | ||
}) | ||
} | ||
}) | ||
} |
Oops, something went wrong.