Compare commits
4 Commits
0.6.1
...
0fa043f0df
Author | SHA1 | Date | |
---|---|---|---|
0fa043f0df
|
|||
7211133aba
|
|||
d957ca52ea
|
|||
231d8ca7ee
|
@@ -1,7 +1,7 @@
|
||||
FROM registry.odit.services/hub/library/node:17.0.1-alpine3.14
|
||||
WORKDIR /app
|
||||
COPY package.json .
|
||||
COPY yarn.lock .
|
||||
# COPY yarn.lock .
|
||||
RUN yarn --production --frozen-lockfile
|
||||
COPY migrations ./migrations
|
||||
COPY src ./src
|
||||
|
@@ -96,6 +96,12 @@ fastify.get('/e/:id', async (req, res) => {
|
||||
await knex('visits').insert({ shortcode: req.params.id, provider: 'e' });
|
||||
})
|
||||
|
||||
//Automagic reddit redirects on /r/
|
||||
fastify.get('/r/:id', async (req, res) => {
|
||||
res.redirect(302, `https://redd.it/${req.params.id}`)
|
||||
await knex('visits').insert({ shortcode: req.params.id, provider: 'r' });
|
||||
})
|
||||
|
||||
//Normal shorturls
|
||||
fastify.get('/:shortcode', async (req, res) => {
|
||||
const shortcode = req.params.shortcode;
|
||||
@@ -437,6 +443,16 @@ function checkKnownProviders(target) {
|
||||
target
|
||||
}
|
||||
}
|
||||
|
||||
const redditID = target.match(/(((((?:https?:)?\/\/)((?!about\.)[\w-]+?\.)?([rc]edd(?:it\.com|\.it)))(?!\/(?:blog|about|code|advertising|jobs|rules|wiki|contact|buttons|gold|page|help|prefs|user|message|widget)\b)((?:\/r\/[\w-]+\b(?<!\/pcmasterrace))|(?:\/tb))?(\/comments)??(\/\w{2,7}\b(?<!\/46ijrl)(?<!\/wiki))((?:(?!\))\S)*)))/);
|
||||
if (redditID[9]) {
|
||||
const shortcode = `r${redditID[9]}`
|
||||
return {
|
||||
url: `${config.getBaseUrl()}/${shortcode}`,
|
||||
shortcode,
|
||||
target
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user