feat: migrate to PostgreSQL GORM and MinIO file storage

Use UUID models and soft deletion, persist file relationships with deduplicated monthly MinIO objects, and add admin file management. Update mini-program media handling and add local dev configuration.
This commit is contained in:
2026-11-01 11:48:45 +08:00
parent 0530523750
commit 4934a69581
94 changed files with 4686 additions and 2147 deletions
+15 -14
View File
@@ -1,22 +1,23 @@
const { fileId, normalizeUploadResult, filePayload } = require('./file-media');
const { camelName, toWire, fromWire } = require('./api-naming');
const dataCache = require('./data-cache');
/**
* 网络请求工具 - 对接后端 API
*/
const API_BASE = 'https://past.sundynix.cn/api';
const MEDIA_BASE = 'https://past.sundynix.cn/backend/';
const { API_BASE } = require('../config/env');
/**
* 将相对路径转为完整URL(供小程序端显示图片使用)
* @param {string} path - 相对路径,如 "uploads/avatars/xxx.jpg"
* @returns {string} 完整URL,如 "http://192.168.2.103/uploads/avatars/xxx.jpg"
* 将文件 UUID 或 /api/files/{id} 转成完整访问地址。
* 完整 URL 和小程序本地图片路径直接使用。
*/
function getImageUrl(path) {
if (!path) return '';
if (typeof path === 'object') path = fileId(path) || path.path || path.url || '';
if (typeof path !== 'string') return '';
if (path.startsWith('/api/files/')) return API_BASE.replace(/\/api$/, '') + path;
if (fileId(path) === path) return API_BASE + '/files/' + path;
if (path.startsWith('http://') || path.startsWith('https://')) return path;
if (path.startsWith('/backend/')) return MEDIA_BASE + path.substring('/backend/'.length);
if (path.startsWith('/')) return MEDIA_BASE + path.substring(1);
return MEDIA_BASE + path;
return path;
}
/**
@@ -26,23 +27,23 @@ function getImageUrl(path) {
*/
function parseUploadResponse(raw) {
if (!raw) return null;
if (typeof raw === 'object') return fromWire(raw);
if (typeof raw === 'object') return normalizeUploadResult(fromWire(raw));
var str = String(raw).trim();
// 去除 BOM 和不可见字符
str = str.replace(/^\uFEFF/, '').replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, '');
try {
return fromWire(JSON.parse(str));
return normalizeUploadResult(fromWire(JSON.parse(str)));
} catch(e) {
// 尝试提取 JSON 片段(Android 端可能返回带额外字符的响应)
var match = str.match(/\{[\s\S]*\}/);
if (match) {
try { return fromWire(JSON.parse(match[0])); } catch(e2) {}
try { return normalizeUploadResult(fromWire(JSON.parse(match[0]))); } catch(e2) {}
}
// 最后尝试:查找 "success" 或 "path" 关键词,手动构建响应对象
if (str.indexOf('success') > -1 || str.indexOf('path') > -1) {
var pathMatch = str.match(/"path"\s*:\s*"([^"]+)"/);
if (pathMatch) {
return { success: true, path: pathMatch[1] };
return normalizeUploadResult({ success: true, path: pathMatch[1] });
}
}
return null;
@@ -129,7 +130,7 @@ function sendRequest(action, data = null, method = 'POST') {
}
let url = API_BASE + '/' + encodeURIComponent(camelName(action));
let requestData = toWire(data);
let requestData = toWire(filePayload(camelName(action), data));
if (method === 'GET' && data) {
const params = [];
@@ -385,7 +386,7 @@ const api = {
songsDelete: (data) => request('songsDelete', data),
// 打卡
smokingInfo: (userId, data = {}) => request("smokingInfo", { page: 1, page_size: 20, ...data, user_id: userId || 0 }, "GET"),
smokingInfo: (userId, data = {}) => request("smokingInfo", { page: 1, page_size: 20, ...data, user_id: userId || "" }, "GET"),
smokingAction: (data) => request("smokingAction", data),
checkinList: (data = {}) => request('checkinList', { page: 1, page_size: 20, ...data }, 'GET'),
checkinAdd: (data) => request('checkinAdd', data),