feat(assets): Bild-Upload ins verbundene Git-Repo (#10) (#26)
Image / Image bauen und pushen (push) Successful in 4m29s
CI / App (npm ci + Build, ESLint, Stylelint, Jest) (push) Successful in 2m40s
CI / Storage (mongo) (push) Successful in 1m35s
CI / Storage (postgres) (push) Successful in 1m30s

Upload-Endpunkt POST /api/git/brews/:editId/assets (Magic Bytes, konfigurierbare Limits HB_ASSET_*, Dedupe, Commit ins Repo, Snapshot in brew_assets) und Auslieferung /git-assets/:shareId/:sha256.:ext gemäß ADR 0004. Postgres-Migration 0003, Mongo-Repo, Editor-Button, Drag-and-drop und Einfügen.

Closes #10

Co-authored-by: Dev (Paperclip) <dev-bot@noreply.git.morlana.online>
This commit was merged in pull request #26.
This commit is contained in:
dev-bot Bot authored and Gitea committed 2026-11-26 01:39:34 +00:00
1 parent bbf838c5d6
commit aeca3926a3
34 files changed
+1353 -11

No files matched your search

+6 -4
View File
@@ -134,6 +134,8 @@ export const createGitService = ({ cfg, getStorage, api, splitTextStyleAndMetada
locks,
canEdit,
isBrewOwner,
loadEditableBrew,
authorOf,
async listConnections(account) {
const uid = requireUid(account);
@@ -214,8 +216,8 @@ export const createGitService = ({ cfg, getStorage, api, splitTextStyleAndMetada
* `expectedBlob`: Blob-ID, die wir zuletzt gesehen haben (null: Datei soll neu sein).
* `overwrite`: Blob-ID aus gitOverwrite (bewusstes Überschreiben des fremden Stands).
*/
async commitContent(conn, { branch, filePath, content, expectedBlob, overwrite, author, signal }) {
if(Buffer.byteLength(content) > cfg.maxFileBytes) throw new GitError('G09');
async commitContent(conn, { branch, filePath, content, expectedBlob, overwrite, author, signal, message: customMessage, maxBytes = cfg.maxFileBytes, ignoreConflict = false }) {
if(Buffer.byteLength(content) > maxBytes) throw new GitError('G09');
for (let attempt = 1; attempt <= MAX_PUSH_ATTEMPTS; attempt++) {
const result = await withConn(conn, async (repo)=>{
const head = await client.fetchHead(repo, branch);
@@ -226,11 +228,11 @@ export const createGitService = ({ cfg, getStorage, api, splitTextStyleAndMetada
if(!parent) throw new GitError('G03', 'Der Standard-Branch der Verbindung existiert im Repository nicht.');
}
const remoteBlob = parent ? await client.blobAt(repo, parent, filePath) : null;
if((remoteBlob ?? null) !== (expectedBlob ?? null) && overwrite !== (remoteBlob ?? 'none')) {
if(!ignoreConflict && (remoteBlob ?? null) !== (expectedBlob ?? null) && overwrite !== (remoteBlob ?? 'none')) {
if(expectedBlob === null && remoteBlob) throw new GitError('G06', undefined, { extra: { remoteCommitSha: parent, remoteBlobSha: remoteBlob } });
throw new GitError('G01', undefined, { extra: { remoteCommitSha: parent, remoteBlobSha: remoteBlob } });
}
const message = `${remoteBlob ? 'Update' : 'Create'} ${filePath} via Homebrewery`;
const message = customMessage ?? `${remoteBlob ? 'Update' : 'Create'} ${filePath} via Homebrewery`;
const { commit, blob } = await client.buildCommit(repo, { parent, filePath, content, author, message, committer });
if(head && blob === remoteBlob) return { commit: head, blob, unchanged: true };
try {
+8 -1
View File
@@ -2,6 +2,8 @@ import { readGitConfig } from './config.js';
import { createGitService } from './brewSync.js';
import { createGitRouter } from './routes.js';
import { configureGitHooks } from './hooks.js';
import express from 'express';
import { createAssetsBackend } from '../assets/index.js';
export { readGitConfig, createGitService, createGitRouter, configureGitHooks };
@@ -14,5 +16,10 @@ export const createGitBackend = ({ getStorage, api, splitTextStyleAndMetadata, e
if(!cfg.enabled) logger.warn?.('Git-Backend deaktiviert: HB_GIT_TOKEN_KEY ist nicht gesetzt (openssl rand -base64 32).');
const service = createGitService({ cfg, getStorage, api, splitTextStyleAndMetadata, logger });
configureGitHooks(cfg.enabled ? service : undefined);
return { service, router: createGitRouter(service, { logger }) };
// Bild-Upload (ADR 0004) hängt vor dem Git-Router, damit POST …/assets die rohen Bilddaten selbst liest
const assets = createAssetsBackend({ gitSvc: service, getStorage, env, logger });
const router = express.Router();
router.use(assets.router);
router.use(createGitRouter(service, { logger }));
return { service, assets: assets.service, router };
};