initial commit

This commit is contained in:
Hampus Kraft
2026-01-01 20:42:59 +00:00
commit 2f557eda8c
9029 changed files with 1490197 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
/*
* Copyright (C) 2026 Fluxer Contributors
*
* This file is part of Fluxer.
*
* Fluxer is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Fluxer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
const EXTERNAL_MODULES = [
'@lingui/cli',
'@lingui/conf',
'cosmiconfig',
'jiti',
'node:*',
'crypto',
'path',
'fs',
'os',
'vm',
'perf_hooks',
'util',
'events',
'stream',
'buffer',
'child_process',
'cluster',
'dgram',
'dns',
'http',
'https',
'module',
'net',
'repl',
'tls',
'url',
'worker_threads',
'readline',
'zlib',
'resolve',
];
const EXTERNAL_PATTERNS = [/^node:.*/];
export class ExternalsPlugin {
apply(compiler) {
const existingExternals = compiler.options.externals || [];
const externalsArray = Array.isArray(existingExternals) ? existingExternals : [existingExternals];
compiler.options.externals = [...externalsArray, ...EXTERNAL_MODULES, ...EXTERNAL_PATTERNS];
}
}
export function externalsPlugin() {
return new ExternalsPlugin();
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright (C) 2026 Fluxer Contributors
*
* This file is part of Fluxer.
*
* Fluxer is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Fluxer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import path from 'node:path';
import {fileURLToPath} from 'node:url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export function getLinguiSwcPluginConfig() {
return [
'@lingui/swc-plugin',
{
localeDir: 'src/locales/{locale}/messages',
runtimeModules: {
i18n: ['@lingui/core', 'i18n'],
trans: ['@lingui/react', 'Trans'],
},
stripNonEssentialFields: false,
},
];
}
export function createPoFileRule() {
return {
test: /\.po$/,
type: 'javascript/auto',
use: {
loader: path.join(__dirname, 'po-loader.mjs'),
},
};
}

View File

@@ -0,0 +1,164 @@
/*
* Copyright (C) 2026 Fluxer Contributors
*
* This file is part of Fluxer.
*
* Fluxer is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Fluxer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import fs from 'node:fs/promises';
export default function poLoader(source) {
const callback = this.async();
(async () => {
try {
this.cacheable?.();
const poPath = this.resourcePath;
const compiledPath = `${poPath}.mjs`;
this.addDependency?.(poPath);
try {
await fs.access(compiledPath);
this.addDependency?.(compiledPath);
const compiledSource = await fs.readFile(compiledPath, 'utf8');
callback(null, compiledSource);
return;
} catch {}
const content = Buffer.isBuffer(source) ? source.toString('utf8') : String(source);
const messages = parsePoFile(content);
const code = `export const messages = ${JSON.stringify(messages, null, 2)};\nexport default messages;\n`;
callback(null, code);
} catch (err) {
callback(err);
}
})();
}
function parsePoFile(content) {
const messages = {};
const entries = splitEntries(content);
for (const entry of entries) {
const parsed = parseEntry(entry);
if (!parsed) continue;
messages[parsed.key] = parsed.value;
}
return messages;
}
function splitEntries(content) {
const normalized = content.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
return normalized
.split(/\n{2,}/g)
.map((s) => s.trim())
.filter(Boolean);
}
function parseEntry(entry) {
const lines = entry.split('\n');
let msgctxt = null;
let msgid = null;
let msgidPlural = null;
const msgstrMap = new Map();
let active = null;
let activeMsgstrIndex = 0;
for (const rawLine of lines) {
const line = rawLine.trim();
if (!line || line.startsWith('#')) continue;
if (line.startsWith('msgctxt ')) {
active = 'msgctxt';
activeMsgstrIndex = 0;
msgctxt = extractPoString(line.slice('msgctxt '.length));
continue;
}
if (line.startsWith('msgid_plural ')) {
active = 'msgidPlural';
activeMsgstrIndex = 0;
msgidPlural = extractPoString(line.slice('msgid_plural '.length));
continue;
}
if (line.startsWith('msgid ')) {
active = 'msgid';
activeMsgstrIndex = 0;
msgid = extractPoString(line.slice('msgid '.length));
continue;
}
const msgstrIndexed = line.match(/^msgstr\[(\d+)\]\s+/);
if (msgstrIndexed) {
active = 'msgstr';
activeMsgstrIndex = Number(msgstrIndexed[1]);
const rest = line.slice(msgstrIndexed[0].length);
msgstrMap.set(activeMsgstrIndex, extractPoString(rest));
continue;
}
if (line.startsWith('msgstr ')) {
active = 'msgstr';
activeMsgstrIndex = 0;
msgstrMap.set(0, extractPoString(line.slice('msgstr '.length)));
continue;
}
if (line.startsWith('"') && line.endsWith('"')) {
const part = extractPoString(line);
if (active === 'msgctxt') msgctxt = (msgctxt ?? '') + part;
else if (active === 'msgid') msgid = (msgid ?? '') + part;
else if (active === 'msgidPlural') msgidPlural = (msgidPlural ?? '') + part;
else if (active === 'msgstr') msgstrMap.set(activeMsgstrIndex, (msgstrMap.get(activeMsgstrIndex) ?? '') + part);
}
}
if (msgid == null) return null;
if (msgid === '') return null;
const key = msgctxt ? `${msgctxt}\u0004${msgid}` : msgid;
if (msgidPlural != null) {
const keys = Array.from(msgstrMap.keys());
const maxIndex = keys.length ? Math.max(...keys.map((n) => Number(n))) : 0;
const arr = [];
for (let i = 0; i <= maxIndex; i++) {
arr[i] = msgstrMap.get(i) ?? '';
}
return {key, value: arr};
}
return {key, value: msgstrMap.get(0) ?? ''};
}
function extractPoString(str) {
const trimmed = str.trim();
if (!trimmed.startsWith('"') || !trimmed.endsWith('"')) return trimmed;
return trimmed.slice(1, -1).replace(/\\n/g, '\n').replace(/\\"/g, '"').replace(/\\\\/g, '\\');
}

View File

@@ -0,0 +1,119 @@
/*
* Copyright (C) 2026 Fluxer Contributors
*
* This file is part of Fluxer.
*
* Fluxer is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Fluxer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {sources} from '@rspack/core';
function normalizeEndpoint(cdnEndpoint) {
if (!cdnEndpoint) return '';
return cdnEndpoint.endsWith('/') ? cdnEndpoint.slice(0, -1) : cdnEndpoint;
}
function generateManifest(cdnEndpointRaw) {
const cdnEndpoint = normalizeEndpoint(cdnEndpointRaw);
const manifest = {
name: 'Fluxer',
short_name: 'Fluxer',
description:
'Chat that puts you first. Built for friends, groups, and communities. Text, voice, and video. Open source and community-funded.',
start_url: '/',
display: 'standalone',
orientation: 'portrait-primary',
theme_color: '#4641D9',
background_color: '#2b2d31',
categories: ['social', 'communication'],
lang: 'en',
scope: '/',
icons: [
{
src: `${cdnEndpoint}/web/android-chrome-192x192.png`,
sizes: '192x192',
type: 'image/png',
purpose: 'maskable any',
},
{
src: `${cdnEndpoint}/web/android-chrome-512x512.png`,
sizes: '512x512',
type: 'image/png',
purpose: 'maskable any',
},
{
src: `${cdnEndpoint}/web/apple-touch-icon.png`,
sizes: '180x180',
type: 'image/png',
},
{
src: `${cdnEndpoint}/web/favicon-32x32.png`,
sizes: '32x32',
type: 'image/png',
},
{
src: `${cdnEndpoint}/web/favicon-16x16.png`,
sizes: '16x16',
type: 'image/png',
},
],
};
return JSON.stringify(manifest, null, 2);
}
function generateBrowserConfig(cdnEndpointRaw) {
const cdnEndpoint = normalizeEndpoint(cdnEndpointRaw);
return `<?xml version="1.0" encoding="utf-8"?>
<browserconfig>
<msapplication>
<tile>
<square150x150logo src="${cdnEndpoint}/web/mstile-150x150.png"/>
<TileColor>#4641D9</TileColor>
</tile>
</msapplication>
</browserconfig>`;
}
function generateRobotsTxt() {
return 'User-agent: *\nAllow: /\n';
}
export class StaticFilesPlugin {
constructor(options) {
this.cdnEndpoint = options?.cdnEndpoint ?? '';
}
apply(compiler) {
compiler.hooks.thisCompilation.tap('StaticFilesPlugin', (compilation) => {
compilation.hooks.processAssets.tap(
{
name: 'StaticFilesPlugin',
stage: compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
},
() => {
compilation.emitAsset('manifest.json', new sources.RawSource(generateManifest(this.cdnEndpoint)));
compilation.emitAsset('browserconfig.xml', new sources.RawSource(generateBrowserConfig(this.cdnEndpoint)));
compilation.emitAsset('robots.txt', new sources.RawSource(generateRobotsTxt()));
},
);
});
}
}
export function staticFilesPlugin(options) {
return new StaticFilesPlugin(options);
}

View File

@@ -0,0 +1,63 @@
/*
* Copyright (C) 2026 Fluxer Contributors
*
* This file is part of Fluxer.
*
* Fluxer is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Fluxer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import * as fs from 'node:fs';
import * as path from 'node:path';
import {fileURLToPath} from 'node:url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export default function wasmLoader(_source) {
const callback = this.async();
if (!callback) {
throw new Error('Async loader not supported');
}
const wasmPath = this.resourcePath;
fs.promises
.readFile(wasmPath)
.then((wasmContent) => {
const base64 = wasmContent.toString('base64');
const code = `
const wasmBase64 = "${base64}";
const wasmBinary = Uint8Array.from(atob(wasmBase64), c => c.charCodeAt(0));
export default wasmBinary;
`;
callback(null, code);
})
.catch((err) => {
callback(err);
});
}
export function wasmModuleRule() {
return {
test: /\.wasm$/,
exclude: [/node_modules/],
type: 'javascript/auto',
use: [
{
loader: path.join(__dirname, 'wasm.mjs'),
},
],
};
}