setup i18n
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Potentially Dangerous Link": "Potentially Dangerous Link",
|
||||||
|
"Blocked Link": "Blocked Link",
|
||||||
|
"This link may be malicious. You should proceed at your own risk.": "This link may be malicious. You should proceed at your own risk.",
|
||||||
|
"This link has been identified as malicious and has blocked for your safety.": "This link has been identified as malicious and has blocked for your safety.",
|
||||||
|
"Continue Anyway": "Continue Anyway",
|
||||||
|
"Return to Bluesky": "Return to Bluesky"
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Potentially Dangerous Link": "Enlace Potencialmente Peligroso",
|
||||||
|
"Blocked Link": "Enlace Bloqueado",
|
||||||
|
"This link may be malicious. You should proceed at your own risk.": "Este enlace puede ser malicioso. Debes proceder bajo tu propio riesgo.",
|
||||||
|
"This link has been identified as malicious and has blocked for your safety.": "Este enlace ha sido identificado como malicioso y ha sido bloqueado por tu seguridad.",
|
||||||
|
"Continue Anyway": "Continuar de Todos Modos",
|
||||||
|
"Return to Bluesky": "Regresar a Bluesky"
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Potentially Dangerous Link": "Lien Potentiellement Dangereux",
|
||||||
|
"Blocked Link": "Lien Bloqué",
|
||||||
|
"This link may be malicious. You should proceed at your own risk.": "Ce lien peut être malveillant. Vous devriez procéder à vos propres risques.",
|
||||||
|
"This link has been identified as malicious and has blocked for your safety.": "Ce lien a été identifié comme malveillant et a été bloqué pour votre sécurité.",
|
||||||
|
"Continue Anyway": "Continuer Quand Même",
|
||||||
|
"Return to Bluesky": "Retourner à Bluesky"
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
"escape-html": "^1.0.3",
|
"escape-html": "^1.0.3",
|
||||||
"express": "^4.19.2",
|
"express": "^4.19.2",
|
||||||
"http-terminator": "^3.2.0",
|
"http-terminator": "^3.2.0",
|
||||||
|
"i18n": "^0.15.1",
|
||||||
"kysely": "^0.27.3",
|
"kysely": "^0.27.3",
|
||||||
"pg": "^8.12.0",
|
"pg": "^8.12.0",
|
||||||
"pino": "^9.2.0",
|
"pino": "^9.2.0",
|
||||||
@@ -23,6 +24,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/cors": "^2.8.17",
|
"@types/cors": "^2.8.17",
|
||||||
|
"@types/i18n": "^0.13.12",
|
||||||
"@types/pg": "^8.11.6",
|
"@types/pg": "^8.11.6",
|
||||||
"typescript": "^5.4.5"
|
"typescript": "^5.4.5"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,29 @@
|
|||||||
import escapeHTML from 'escape-html'
|
import escapeHTML from 'escape-html'
|
||||||
|
import {type Request} from 'express'
|
||||||
import {type Hole, html} from 'uhtml'
|
import {type Hole, html} from 'uhtml'
|
||||||
|
|
||||||
export function linkWarningContents(opts: {
|
export function linkWarningContents(
|
||||||
|
req: Request,
|
||||||
|
opts: {
|
||||||
type: 'warn' | 'block'
|
type: 'warn' | 'block'
|
||||||
link: string
|
link: string
|
||||||
}): Hole {
|
},
|
||||||
|
): Hole {
|
||||||
return html`
|
return html`
|
||||||
<div class="warning-icon">⚠️</div>
|
<div class="warning-icon">⚠️</div>
|
||||||
<h1>
|
<h1>
|
||||||
${opts.type === 'warn' ? 'Potentially Dangerous Link' : 'Blocked Link'}
|
${opts.type === 'warn'
|
||||||
|
? req.__('Potentially Dangerous Link')
|
||||||
|
: req.__('Blocked Link')}
|
||||||
</h1>
|
</h1>
|
||||||
<p class="warning-text">
|
<p class="warning-text">
|
||||||
${opts.type === 'warn'
|
${opts.type === 'warn'
|
||||||
? 'This link may be malicious. You should proceed at your own risk.'
|
? req.__(
|
||||||
: 'This link has been identified as malicious and has blocked for your safety.'}
|
'This link may be malicious. You should proceed at your own risk.',
|
||||||
|
)
|
||||||
|
: req.__(
|
||||||
|
'This link has been identified as malicious and has blocked for your safety.',
|
||||||
|
)}
|
||||||
</p>
|
</p>
|
||||||
<div class="blocked-site">
|
<div class="blocked-site">
|
||||||
<p class="site-url">${escapeHTML(opts.link)}</p>
|
<p class="site-url">${escapeHTML(opts.link)}</p>
|
||||||
@@ -21,10 +31,12 @@ export function linkWarningContents(opts: {
|
|||||||
<div class="button-group">
|
<div class="button-group">
|
||||||
${opts.type === 'warn'
|
${opts.type === 'warn'
|
||||||
? html`<a class="button secondary" href="${escapeHTML(opts.link)}"
|
? html`<a class="button secondary" href="${escapeHTML(opts.link)}"
|
||||||
>Continue Anyway</a
|
>${req.__('Continue Anyway')}</a
|
||||||
>`
|
>`
|
||||||
: null}
|
: null}
|
||||||
<a class="button primary" href="https://bsky.app">Return to Bluesky</a>
|
<a class="button primary" href="https://bsky.app"
|
||||||
|
>${req.__('Return to Bluesky')}</a
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import path from 'node:path'
|
||||||
|
import {fileURLToPath} from 'node:url'
|
||||||
|
|
||||||
|
import i18n from 'i18n'
|
||||||
|
|
||||||
|
const __filename = fileURLToPath(import.meta.url)
|
||||||
|
const __dirname = path.dirname(__filename)
|
||||||
|
|
||||||
|
i18n.configure({
|
||||||
|
locales: ['en', 'es', 'fr'],
|
||||||
|
defaultLocale: 'en',
|
||||||
|
directory: path.join(__dirname, '../locales'),
|
||||||
|
})
|
||||||
|
|
||||||
|
export default i18n
|
||||||
@@ -7,6 +7,7 @@ import {createHttpTerminator, type HttpTerminator} from 'http-terminator'
|
|||||||
|
|
||||||
import {type Config} from './config.js'
|
import {type Config} from './config.js'
|
||||||
import {AppContext} from './context.js'
|
import {AppContext} from './context.js'
|
||||||
|
import i18n from './i18n.js'
|
||||||
import {default as routes, errorHandler} from './routes/index.js'
|
import {default as routes, errorHandler} from './routes/index.js'
|
||||||
|
|
||||||
export * from './config.js'
|
export * from './config.js'
|
||||||
@@ -17,11 +18,15 @@ export class LinkService {
|
|||||||
public server?: http.Server
|
public server?: http.Server
|
||||||
private terminator?: HttpTerminator
|
private terminator?: HttpTerminator
|
||||||
|
|
||||||
constructor(public app: express.Application, public ctx: AppContext) {}
|
constructor(
|
||||||
|
public app: express.Application,
|
||||||
|
public ctx: AppContext,
|
||||||
|
) {}
|
||||||
|
|
||||||
static async create(cfg: Config): Promise<LinkService> {
|
static async create(cfg: Config): Promise<LinkService> {
|
||||||
let app = express()
|
let app = express()
|
||||||
app.use(cors())
|
app.use(cors())
|
||||||
|
app.use(i18n.init)
|
||||||
|
|
||||||
const ctx = await AppContext.fromConfig(cfg)
|
const ctx = await AppContext.fromConfig(cfg)
|
||||||
app = routes(ctx, app)
|
app = routes(ctx, app)
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ export default function (ctx: AppContext, app: Express) {
|
|||||||
case ToolsOzoneSafelinkDefs.BLOCK:
|
case ToolsOzoneSafelinkDefs.BLOCK:
|
||||||
hole = linkWarningLayout(
|
hole = linkWarningLayout(
|
||||||
'Blocked Link Warning',
|
'Blocked Link Warning',
|
||||||
linkWarningContents({
|
linkWarningContents(req, {
|
||||||
type: 'block',
|
type: 'block',
|
||||||
link: url.href,
|
link: url.href,
|
||||||
}),
|
}),
|
||||||
@@ -79,7 +79,7 @@ export default function (ctx: AppContext, app: Express) {
|
|||||||
case ToolsOzoneSafelinkDefs.WARN:
|
case ToolsOzoneSafelinkDefs.WARN:
|
||||||
hole = linkWarningLayout(
|
hole = linkWarningLayout(
|
||||||
'Malicious Link Warning',
|
'Malicious Link Warning',
|
||||||
linkWarningContents({
|
linkWarningContents(req, {
|
||||||
type: 'warn',
|
type: 'warn',
|
||||||
link: url.href,
|
link: url.href,
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user