Skip to content

Fixes for Brand Link Format, Private Link Addition #819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ RATE_LIMIT_LONG_MAX=200
## How long to wait before the backend gives up scraping a link
LINK_TIMEOUT=15 seconds

## Add the link anyway. Need for private link with auth
USE_ANY_LINK_STATUS=false

## How long the cache should last for a redirect/301
CACHE_MAX_AGE=10 years

Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# syntax=docker/dockerfile:1
#----------------------------------------#
# dev/test
FROM node:lts-alpine AS deps
FROM node:18.17-alpine AS deps
RUN apk add --no-cache --virtual .gyp python3 make g++ libc6-compat && \
npm i -g npm
ENV NPM_CONFIG_PREFER_OFFLINE=true
Expand All @@ -19,7 +19,7 @@ COPY --chown=node:node . .

#----------------------------------------#
# We have a separate build container to persist build artifacts & production npm deps
FROM node:lts-alpine AS build
FROM node:18.17-alpine AS build
RUN apk add --no-cache --virtual .gyp python3 make g++ libc6-compat && \
npm i -g npm
ENV NPM_CONFIG_PREFER_OFFLINE=true
Expand All @@ -37,7 +37,7 @@ RUN npm run build && \


#----------------------------------------#
FROM node:lts-alpine AS runner
FROM node:18.17-alpine AS runner
RUN apk add --no-cache tini

USER node
Expand Down
4 changes: 4 additions & 0 deletions lib/scrape.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ module.exports = async url => {
})
return metascraper({ html, url: finalUrl })
} catch (err) {
if (process.env.USE_ANY_LINK_STATUS == 'true') {
requestLogger.warn(`Ignoring error for URL ${url} due to USE_ANY_LINK_STATUS:`, err.message)
return null
}
if (err.name === 'RequestError' && err.code === 'ENOTFOUND')
throw httpError(404, 'The address to shorten does not exist!')
if (err.name === 'TimeoutError')
Expand Down
6 changes: 6 additions & 0 deletions models/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ const { URL } = require('url')
const normalizeUrl = require('normalize-url')
const domain = new URL(process.env.BASE_URL).host


class Link extends hashId(BaseModel) {

static get hashIdAlphabet() {
return 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_';
}

static get relationMappings() {
return {
creator: {
Expand Down