Skip to content

Commit

Permalink
Merge pull request #743 from podverse/develop
Browse files Browse the repository at this point in the history
Release v4.16.12
  • Loading branch information
mitchdowney authored Apr 22, 2024
2 parents f8f9556 + 9a3331b commit fab7977
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "podverse-api",
"version": "4.16.11",
"version": "4.16.12",
"description": "Data API, database migration scripts, and backend services for all Podverse models.",
"contributors": [
"Mitch Downey"
Expand Down
18 changes: 16 additions & 2 deletions src/routes/tools.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as Router from 'koa-router'
import { config } from '~/config'
import { emitRouterError } from '~/lib/errors'
import { getFinalRedirectedUrl } from '~/lib/request'
import { getFinalRedirectedUrl, request } from '~/lib/request'
const createError = require('http-errors')

const router = new Router({ prefix: `${config.apiPrefix}${config.apiVersion}/tools` })

Expand All @@ -28,7 +29,20 @@ const extractHTTPSFromURL = async (url, tries) => {
return url
} else {
const redirectedUrl = await getFinalRedirectedUrl(url)
return redirectedUrl
let finalUrl = redirectedUrl

if (redirectedUrl.startsWith('http://')) {
try {
const attemptHttpsUrl = redirectedUrl.replace('http://', 'https://')
// If no error is thrown,then assume it is a valid url.
await request(attemptHttpsUrl, { followRedirect: true, method: 'head' })
finalUrl = attemptHttpsUrl
} catch (error) {
throw new createError.NotFound('Secure URL for ' + url + ' was not found.')
}
}

return finalUrl
}
} catch (error) {
if (['301', '302', '303', '307', '308'].includes(String(error.statusCode))) {
Expand Down
4 changes: 2 additions & 2 deletions src/services/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ const generateResetToZeroQueryString = (finalPagePath: string, timeRange, id: st
queryString = `
UPDATE "episodes" AS e
SET "${TimeRanges[timeRange]}" = 0
WHERE id = ${id}
WHERE id = '${id}'
AND "podcastId"
IN (
SELECT p.id
Expand All @@ -248,7 +248,7 @@ const generateResetToZeroQueryString = (finalPagePath: string, timeRange, id: st
queryString = `
UPDATE "episodes" AS e
SET "${TimeRanges[timeRange]}" = 0
WHERE id = ${id}
WHERE id = '${id}'
AND "podcastId"
IN (
SELECT p.id
Expand Down

0 comments on commit fab7977

Please sign in to comment.