feat(koi): sharkey improvements

- updated to latest develop
- fixed nginx upload limit
- added locale and stats patching
This commit is contained in:
alina 🌸 2024-03-14 14:32:28 +03:00
parent e89b7eeb63
commit 6480920fde
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
5 changed files with 110 additions and 15 deletions

View file

@ -1,7 +1,12 @@
FROM registry.activitypub.software/transfem-org/sharkey:develop@sha256:44289651333c9fe6dd11773c42d631bcc3a7e9ba78de5b17b31654e1b731e598 FROM registry.activitypub.software/transfem-org/sharkey:develop@sha256:fd6c17901d7103d38837e6415b4e34fbf641e82961a6ec9d7e9c249f4779cf4e
COPY patches /patches COPY patches /patches
RUN apk add patch && \ USER root
patch -p0 < /patches/zond.patch && \ RUN apk add patch
patch -p0 < /patches/software.patch USER sharkey
RUN patch -p0 < /patches/zond.patch && \
patch -p0 < /patches/software.patch && \
patch -p0 < /patches/stats.patch && \
node /patches/patch-locale.js

View file

@ -16,6 +16,10 @@
forceSSL = true; forceSSL = true;
useACMEHost = "stupid.fish"; useACMEHost = "stupid.fish";
extraConfig = ''
client_max_body_size 250M;
'';
locations."/" = { locations."/" = {
proxyPass = "http://web.sharkey.docker/"; proxyPass = "http://web.sharkey.docker/";
proxyWebsockets = true; proxyWebsockets = true;

View file

@ -1,11 +0,0 @@
--- packages/backend/built/server/api/endpoints/notes/translate.js
+++ packages/backend/built/server/api/endpoints/notes/translate.js
@@ -99,7 +99,7 @@
params.append('auth_key', instance.deeplAuthKey);
params.append('text', note.text);
params.append('target_lang', targetLang);
- const endpoint = instance.deeplIsPro ? 'https://api.deepl.com/v2/translate' : 'https://api-free.deepl.com/v2/translate';
+ const endpoint = 'https://tei.su/api/fake-deepl/v2/translate';
const res = await this.httpRequestService.send(endpoint, {
method: 'POST',
headers: {

View file

@ -0,0 +1,72 @@
const fs = require('fs')
const path = require('path')
const LOCALES_DIR = '/sharkey/built/_frontend_dist_/locales'
const locales = fs.readdirSync(LOCALES_DIR)
const enLocale = locales.find(locale => locale.startsWith('en-US.') && locale.endsWith('.json'))
if (!enLocale) {
throw new Error('en-US locale not found')
}
function parseInterpolations(str) {
const regex = /{([^}]+)}/g
const matches = str.match(regex)
if (!matches) {
return { parts: [str], variables: [] }
}
const parts = []
const variables = []
let lastIndex = 0
for (const match of matches) {
const index = str.indexOf(match)
const part = str.slice(lastIndex, index)
parts.push(part)
const variable = match.slice(1, -1)
variables.push(variable)
lastIndex = index + match.length
}
const lastPart = str.slice(lastIndex)
parts.push(lastPart)
return { parts, variables }
}
function unparseInterpolations({ parts, variables }) {
let str = parts[0]
for (let i = 0; i < variables.length; i++) {
str += `{${variables[i]}}${parts[i + 1]}`
}
return str
}
const enLocaleFull = path.join(LOCALES_DIR, enLocale)
const json = JSON.parse(fs.readFileSync(enLocaleFull, 'utf8'))
// recursively make every string lowercase
function patchObject(obj) {
for (const [key, value] of Object.entries(obj)) {
if (typeof value === 'object') {
patchObject(value)
continue
}
if (typeof value !== 'string') {
continue
}
const { parts, variables } = parseInterpolations(value)
const lowercasedParts = parts.map(part => part.toLowerCase())
const newValue = unparseInterpolations({ parts: lowercasedParts, variables })
obj[key] = newValue
}
}
patchObject(json)
fs.writeFileSync(enLocaleFull, JSON.stringify(json, null))

View file

@ -0,0 +1,25 @@
--- packages/backend/built/server/api/endpoints/stats.js
+++ packages/backend/built/server/api/endpoints/stats.js
@@ -85,8 +85,8 @@
const originalNotesCount = notesChart.local.total[0];
const usersChart = await this.usersChart.getChart('hour', 1, null);
- const usersCount = usersChart.local.total[0] + usersChart.remote.total[0];
- const originalUsersCount = usersChart.local.total[0];
+ const usersCount = 1 + usersChart.remote.total[0];
+ const originalUsersCount = 1;
const [reactionsCount, //originalReactionsCount,
instances] = await Promise.all([
this.noteReactionsRepository.count({
--- packages/backend/built/server/NodeinfoServerService.js
+++ packages/backend/built/server/NodeinfoServerService.js
@@ -58,8 +58,7 @@
const now = Date.now();
const notesChart = await this.notesChart.getChart('hour', 1, null);
const localPosts = notesChart.local.total[0];
- const usersChart = await this.usersChart.getChart('hour', 1, null);
- const total = usersChart.local.total[0];
+ const total = 1;
const [meta] = await Promise.all([
this.metaService.fetch(true)
]);