mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-06-21 21:53:50 +08:00
!397 支持使用debian脚本构建deb包、新增投稿器(初稿)
Merge pull request !397 from gfdgd xi/Erotica
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
.DEFAULT_GOAL := build
|
||||
|
||||
clean:
|
||||
rm -rf release/
|
||||
|
||||
build:
|
||||
npm run build:deb
|
||||
|
||||
install:
|
||||
mkdir -p $(DESTDIR)/opt/spark-store/bin/
|
||||
mkdir -p $(DESTDIR)/opt/spark-store/extras/
|
||||
mkdir -p $(DESTDIR)/opt/durapps/spark-store/bin/
|
||||
mkdir -p $(DESTDIR)/usr/share/icons/
|
||||
mkdir -p $(DESTDIR)/usr/lib/
|
||||
mkdir -p $(DESTDIR)/usr/bin/
|
||||
cp -rv release/*/linux-unpacked/* $(DESTDIR)/opt/spark-store/bin/
|
||||
cp -rv release/*/linux-unpacked/extras/* $(DESTDIR)/opt/spark-store/extras/
|
||||
cp -rv tool/* $(DESTDIR)/opt/durapps/spark-store/bin/
|
||||
cp -rv pkg/usr/share/fish/ $(DESTDIR)/usr/share/
|
||||
cp -rv icons/hicolor/ $(DESTDIR)/usr/share/icons/
|
||||
cp -rv pkg/usr/share/icons/hicolor/ $(DESTDIR)/usr/share/icons/
|
||||
cp -rv pkg/usr/lib/systemd $(DESTDIR)/usr/lib/
|
||||
cp -rv pkg/usr/share/applications/ $(DESTDIR)/usr/share/
|
||||
cp -rv pkg/usr/share/polkit-1 $(DESTDIR)/usr/share/
|
||||
cp -rv pkg/usr/share/aptss $(DESTDIR)/usr/share/
|
||||
cp -rv tool/spark-store.asc $(DESTDIR)/opt/durapps/spark-store/bin/
|
||||
ln -s ../../../spark-store/extras/spark-store $(DESTDIR)/opt/durapps/spark-store/bin/spark-store
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
spark-store (5.2.0~alpha1) UNRELEASED; urgency=medium
|
||||
|
||||
* Initial release. (Closes: #nnnn) <nnnn is the bug number of your ITP>
|
||||
|
||||
-- shenmo <shenmo@spark-app.store> Tue, 16 Jun 2026 21:45:35 +0800
|
||||
Vendored
+40
@@ -0,0 +1,40 @@
|
||||
Source: spark-store
|
||||
Section: utils
|
||||
Priority: optional
|
||||
Maintainer: shenmo <shenmo@spark-app.store>
|
||||
Rules-Requires-Root: no
|
||||
Build-Depends:
|
||||
debhelper-compat (= 13),
|
||||
make,
|
||||
npm,
|
||||
Standards-Version: 4.7.2
|
||||
Homepage: https://www.spark-app.store/
|
||||
|
||||
Package: spark-store
|
||||
Architecture: any
|
||||
Provides: spark-store-console-in-container
|
||||
Depends:
|
||||
${shlibs:Depends},
|
||||
${misc:Depends},
|
||||
libgtk-3-0,
|
||||
libnotify4,
|
||||
libnss3,
|
||||
libxss1,
|
||||
libxtst6,
|
||||
xdg-utils,
|
||||
libatspi2.0-0,
|
||||
libuuid1,
|
||||
libsecret-1-0,
|
||||
xdg-utils,
|
||||
shared-mime-info,
|
||||
aria2,
|
||||
gnupg,
|
||||
zenity,
|
||||
policykit-1 | pkexec,
|
||||
libnotify-bin,
|
||||
desktop-file-utils,
|
||||
lsb-release,
|
||||
systemd,
|
||||
curl
|
||||
Description: Spark Store
|
||||
A community powered app store, powered by APM.
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
#!/bin/bash
|
||||
|
||||
case "$1" in
|
||||
configure)
|
||||
|
||||
case `arch` in
|
||||
x86_64)
|
||||
echo "Enabling i386 arch..."
|
||||
dpkg --add-architecture i386
|
||||
;;
|
||||
|
||||
aarch64)
|
||||
echo "Will not enable armhf since 4271"
|
||||
;;
|
||||
loongarch64)
|
||||
echo "Nope we DO NOT WANT ABI1 now"
|
||||
dpkg --remove-architecture loongarch64
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Unknown architecture, skip enable 32-bit arch"
|
||||
;;
|
||||
esac
|
||||
|
||||
mkdir -p /var/lib/aptss/lists
|
||||
|
||||
# Remove the sources.list file
|
||||
rm -f /etc/apt/sources.list.d/sparkstore.list
|
||||
rm -f /opt/durapps/spark-store/bin/apt-fast-conf/sources.list.d/sparkstore.list
|
||||
|
||||
# Check if /usr/local/bin existed
|
||||
mkdir -p /usr/local/bin
|
||||
## I hate /usr/local/bin. We will abandon them later
|
||||
# Create symbol links for binary files
|
||||
ln -s -f /opt/durapps/spark-store/bin/spark-store /usr/local/bin/spark-store
|
||||
ln -s -f /opt/durapps/spark-store/bin/ssinstall /usr/local/bin/ssinstall
|
||||
ln -s -f /opt/durapps/spark-store/bin/ssaudit /usr/local/bin/ssaudit
|
||||
ln -s -f /opt/durapps/spark-store/bin/ssinstall /usr/bin/ssinstall
|
||||
ln -s -f /opt/durapps/spark-store/bin/ssaudit /usr/bin/ssaudit
|
||||
ln -s -f /opt/durapps/spark-store/bin/spark-dstore-patch /usr/local/bin/spark-dstore-patch
|
||||
ln -s -f /opt/durapps/spark-store/bin/spark-dstore-patch /usr/bin/spark-dstore-patch
|
||||
ln -s -f /opt/durapps/spark-store/bin/aptss /usr/local/bin/ss-apt-fast
|
||||
|
||||
ln -s -f /opt/durapps/spark-store/bin/aptss /usr/bin/aptss
|
||||
|
||||
|
||||
|
||||
# Install key
|
||||
mkdir -p /tmp/spark-store-install/
|
||||
cp -f /opt/durapps/spark-store/bin/spark-store.asc /tmp/spark-store-install/spark-store.asc
|
||||
gpg --dearmor /tmp/spark-store-install/spark-store.asc
|
||||
cp -f /tmp/spark-store-install/spark-store.asc.gpg /etc/apt/trusted.gpg.d/spark-store.gpg
|
||||
|
||||
|
||||
|
||||
# Start upgrade detect service
|
||||
systemctl daemon-reload
|
||||
systemctl enable spark-update-notifier
|
||||
systemctl start spark-update-notifier
|
||||
|
||||
|
||||
# Update certain caches
|
||||
cp -fv /opt/spark-store/extras/store.spark-app.spark-store.policy /usr/share/polkit-1/actions/store.spark-app.spark-store.policy
|
||||
xdg-mime default spark-store.desktop x-scheme-handler/spk
|
||||
update-mime-database /usr/share/mime || true
|
||||
|
||||
# Send email for statistics
|
||||
#/tmp/spark-store-install/feedback.sh
|
||||
|
||||
# Remove temp dir
|
||||
rm -rf /tmp/spark-store-install
|
||||
;;
|
||||
|
||||
triggered)
|
||||
spark-dstore-patch
|
||||
|
||||
;;
|
||||
esac
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
rm -fv /usr/share/polkit-1/actions/store.spark-app.spark-store.policy
|
||||
|
||||
# Update certain caches
|
||||
update-icon-caches /usr/share/icons/hicolor || true
|
||||
update-desktop-database /usr/share/applications || true
|
||||
update-mime-database /usr/share/mime || true
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
#检测网络链接畅通
|
||||
function network-check()
|
||||
{
|
||||
#超时时间
|
||||
local timeout=15
|
||||
|
||||
#目标网站
|
||||
local target=www.baidu.com
|
||||
|
||||
#获取响应状态码
|
||||
local ret_code=`curl -I -s --connect-timeout ${timeout} ${target} -w %{http_code} | tail -n1`
|
||||
|
||||
if [ "x$ret_code" = "x200" ]; then
|
||||
echo "Network Checked successful ! Continue..."
|
||||
echo "网络通畅,继续安装"
|
||||
else
|
||||
#网络不畅通
|
||||
echo "Network failed ! Cancel the installation"
|
||||
echo "网络不畅,终止安装"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
|
||||
#network-check
|
||||
echo "不再检测网络"
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
#!/bin/bash
|
||||
|
||||
function notify-send()
|
||||
{
|
||||
# Detect the user using such display
|
||||
local user=$(who | awk '{print $1}' | head -n 1)
|
||||
|
||||
# Detect the id of the user
|
||||
local uid=$(id -u $user)
|
||||
|
||||
sudo -u $user DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$uid/bus notify-send "$@"
|
||||
}
|
||||
|
||||
if [ "$1" = "remove" -o "$1" = "purge" ] ; then
|
||||
echo "$1"
|
||||
echo "卸载操作,进行配置清理"
|
||||
|
||||
# Remove residual symbol links
|
||||
unlink /usr/local/bin/spark-store
|
||||
unlink /usr/local/bin/ssinstall
|
||||
unlink /usr/local/bin/ssaudit
|
||||
unlink /usr/bin/ssinstall
|
||||
unlink /usr/bin/ssaudit
|
||||
unlink /usr/local/bin/spark-dstore-patch
|
||||
unlink /usr/bin/spark-dstore-patch
|
||||
unlink /usr/local/bin/ss-apt-fast
|
||||
unlink /usr/bin/aptss
|
||||
|
||||
rm -rf /etc/aptss/
|
||||
rm -rf /var/lib/aptss/
|
||||
|
||||
# Remove residual symbol links to stop upgrade detect
|
||||
rm -f /etc/xdg/autostart/spark-update-notifier.desktop
|
||||
# Remove config files
|
||||
for username in `ls /home`
|
||||
do
|
||||
echo /home/$username
|
||||
if [ -d /home/$username/.config/spark-union/spark-store ]
|
||||
then
|
||||
rm -rf /home/$username/.config/spark-union/spark-store
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
# Shutdown services
|
||||
systemctl stop spark-update-notifier
|
||||
# Stop update detect service
|
||||
systemctl disable spark-update-notifier
|
||||
|
||||
|
||||
|
||||
# Remove gpg key file
|
||||
rm -f /etc/apt/trusted.gpg.d/spark-store.gpg
|
||||
apt-key del '9D9A A859 F750 24B1 A1EC E16E 0E41 D354 A29A 440C' || true
|
||||
else
|
||||
|
||||
if [ ! -z "`pidof spark-store`" ] ; then
|
||||
echo "关闭已有 spark-store.."
|
||||
notify-send "正在升级星火商店" "请在升级结束后重启星火商店" -i spark-store
|
||||
killall spark-store
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/make -f
|
||||
|
||||
# See debhelper(7) (uncomment to enable).
|
||||
# Output every command that modifies files on the build system.
|
||||
#export DH_VERBOSE = 1
|
||||
|
||||
|
||||
# See FEATURE AREAS in dpkg-buildflags(1).
|
||||
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all
|
||||
|
||||
# See ENVIRONMENT in dpkg-buildflags(1).
|
||||
# Package maintainers to append CFLAGS.
|
||||
#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic
|
||||
# Package maintainers to append LDFLAGS.
|
||||
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
|
||||
|
||||
|
||||
%:
|
||||
dh $@
|
||||
|
||||
override_dh_dwz:
|
||||
true
|
||||
|
||||
override_dh_strip:
|
||||
true
|
||||
|
||||
override_dh_shlibdeps:
|
||||
true
|
||||
|
||||
# dh_make generated override targets.
|
||||
# This is an example for Cmake (see <https://bugs.debian.org/641051>).
|
||||
#override_dh_auto_configure:
|
||||
# dh_auto_configure -- \
|
||||
# -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
3.0 (quilt)
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
interest-noawait /opt/apps
|
||||
|
||||
@@ -84,7 +84,8 @@ export function handleCommandLine(commandLine: string[]) {
|
||||
// Handle apt:// protocol: convert to spk://search/pkgname
|
||||
if (url.protocol === "apt:") {
|
||||
// Format: apt://pkgname
|
||||
const pkgname = url.hostname || url.pathname.split("/").filter(Boolean)[0];
|
||||
const pkgname =
|
||||
url.hostname || url.pathname.split("/").filter(Boolean)[0];
|
||||
if (pkgname) {
|
||||
const query: Query = { pkgname };
|
||||
logger.info(`Deep link: apt protocol converted to search: ${pkgname}`);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
app,
|
||||
BrowserWindow,
|
||||
dialog,
|
||||
ipcMain,
|
||||
Menu,
|
||||
nativeImage,
|
||||
@@ -14,6 +15,7 @@ import path from "node:path";
|
||||
import os from "node:os";
|
||||
import fs from "node:fs";
|
||||
import pino from "pino";
|
||||
import https from "node:https";
|
||||
import { handleCommandLine } from "./deeplink.js";
|
||||
import { isLoaded } from "../global.js";
|
||||
import { tasks } from "./backend/install-manager.js";
|
||||
@@ -104,6 +106,7 @@ if (!app.requestSingleInstanceLock()) {
|
||||
}
|
||||
|
||||
let win: BrowserWindow | null = null;
|
||||
let submitterWin: BrowserWindow | null = null;
|
||||
let allowAppExit = false;
|
||||
const preload = path.join(__dirname, "../preload/index.mjs");
|
||||
const indexHtml = path.join(RENDERER_DIST, "index.html");
|
||||
@@ -428,6 +431,908 @@ ipcMain.handle("check-for-updates", async () => {
|
||||
}
|
||||
});
|
||||
|
||||
// 启动投稿器窗口
|
||||
ipcMain.handle("launch-submitter", async () => {
|
||||
try {
|
||||
if (submitterWin && !submitterWin.isDestroyed()) {
|
||||
submitterWin.show();
|
||||
submitterWin.focus();
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
submitterWin = new BrowserWindow({
|
||||
title: "星火应用商店 - 投稿应用",
|
||||
width: 800,
|
||||
height: 900,
|
||||
frame: false,
|
||||
autoHideMenuBar: true,
|
||||
icon: path.join(process.env.VITE_PUBLIC, "favicon.ico"),
|
||||
webPreferences: {
|
||||
preload,
|
||||
},
|
||||
});
|
||||
|
||||
if (VITE_DEV_SERVER_URL) {
|
||||
submitterWin.loadURL(`${VITE_DEV_SERVER_URL}#submitter`);
|
||||
} else {
|
||||
submitterWin.loadFile(indexHtml, { hash: "submitter" });
|
||||
}
|
||||
|
||||
submitterWin.on("closed", () => {
|
||||
submitterWin = null;
|
||||
});
|
||||
|
||||
submitterWin.webContents.setWindowOpenHandler(({ url }) => {
|
||||
if (url.startsWith("https:")) shell.openExternal(url);
|
||||
return { action: "deny" };
|
||||
});
|
||||
|
||||
logger.info("Submitter window opened");
|
||||
return { success: true };
|
||||
} catch (err) {
|
||||
logger.error({ err }, "Failed to open submitter window");
|
||||
return { success: false, message: (err as Error)?.message || String(err) };
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.on("close-submitter-window", () => {
|
||||
submitterWin?.close();
|
||||
});
|
||||
|
||||
interface DebInfo {
|
||||
pkgname: string;
|
||||
version: string;
|
||||
author: string;
|
||||
maintainer: string;
|
||||
homepage: string;
|
||||
description: string;
|
||||
architecture: string;
|
||||
}
|
||||
|
||||
interface HistoryAppInfo {
|
||||
id: number;
|
||||
name: string;
|
||||
pkgname: string;
|
||||
version: string;
|
||||
store: string;
|
||||
author: string;
|
||||
contributor: string;
|
||||
website: string;
|
||||
category: string;
|
||||
tags: string;
|
||||
more: string;
|
||||
icon: string;
|
||||
imgs: string[];
|
||||
}
|
||||
|
||||
ipcMain.handle("select-deb-file", async (_event) => {
|
||||
try {
|
||||
const result = await dialog.showOpenDialog({
|
||||
title: "选择 deb 安装包",
|
||||
filters: [{ name: "Debian 包", extensions: ["deb"] }],
|
||||
properties: ["openFile"],
|
||||
});
|
||||
|
||||
if (!result.canceled && result.filePaths.length > 0) {
|
||||
return { success: true, filePath: result.filePaths[0] };
|
||||
}
|
||||
|
||||
return { success: false, message: "用户取消选择" };
|
||||
} catch (err) {
|
||||
logger.error({ err }, "Failed to select deb file");
|
||||
return { success: false, message: (err as Error)?.message || "选择文件失败" };
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.handle("parse-deb-file", async (_event, debPath: string) => {
|
||||
try {
|
||||
logger.info({ debPath }, "[Submitter] Starting parse-deb-file handler");
|
||||
|
||||
const { exec } = await import("node:child_process");
|
||||
const util = await import("util");
|
||||
const execAsync = util.promisify(exec);
|
||||
|
||||
const absoluteDebPath = path.resolve(debPath);
|
||||
logger.info({ debPath, absoluteDebPath }, "[Submitter] Resolved absolute deb path");
|
||||
|
||||
if (!fs.existsSync(absoluteDebPath)) {
|
||||
logger.error({ debPath, absoluteDebPath }, "[Submitter] Deb file not found");
|
||||
return { success: false, message: `文件不存在: ${absoluteDebPath}` };
|
||||
}
|
||||
|
||||
logger.info({ absoluteDebPath }, "[Submitter] Deb file exists, executing dpkg-deb command");
|
||||
|
||||
const { stdout, stderr } = await execAsync(
|
||||
`dpkg-deb -f "${absoluteDebPath}" Package Version Maintainer Homepage Description Architecture`,
|
||||
);
|
||||
|
||||
logger.info({ stdout, stderr }, "[Submitter] dpkg-deb command executed");
|
||||
|
||||
if (stderr) {
|
||||
logger.error({ stderr }, "[Submitter] dpkg-deb returned error");
|
||||
return { success: false, message: stderr };
|
||||
}
|
||||
|
||||
const lines = stdout.trim().split("\n");
|
||||
logger.info({ lineCount: lines.length, rawOutput: stdout }, "[Submitter] Parsing dpkg-deb output");
|
||||
|
||||
const debInfo: DebInfo = {
|
||||
pkgname: "",
|
||||
version: "",
|
||||
author: "",
|
||||
maintainer: "",
|
||||
homepage: "",
|
||||
description: "",
|
||||
architecture: "",
|
||||
};
|
||||
|
||||
for (const line of lines) {
|
||||
const [key, ...valueParts] = line.split(":");
|
||||
const value = valueParts.join(":").trim();
|
||||
logger.debug({ line, key, value }, "[Submitter] Processing dpkg-deb line");
|
||||
|
||||
switch (key.trim()) {
|
||||
case "Package":
|
||||
debInfo.pkgname = value.toLowerCase();
|
||||
logger.info({ pkgname: debInfo.pkgname }, "[Submitter] Found Package name");
|
||||
break;
|
||||
case "Version":
|
||||
debInfo.version = value;
|
||||
logger.info({ version: debInfo.version }, "[Submitter] Found Version");
|
||||
break;
|
||||
case "Maintainer":
|
||||
debInfo.maintainer = value;
|
||||
debInfo.author = value;
|
||||
logger.info({ maintainer: debInfo.maintainer }, "[Submitter] Found Maintainer");
|
||||
break;
|
||||
case "Homepage":
|
||||
debInfo.homepage = value;
|
||||
logger.info({ homepage: debInfo.homepage }, "[Submitter] Found Homepage");
|
||||
break;
|
||||
case "Description":
|
||||
debInfo.description = value;
|
||||
logger.info({ description: debInfo.description.substring(0, 100) + "..." }, "[Submitter] Found Description");
|
||||
break;
|
||||
case "Architecture":
|
||||
debInfo.architecture = value;
|
||||
logger.info({ architecture: debInfo.architecture }, "[Submitter] Found Architecture");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
logger.info({ debInfo }, "[Submitter] Deb file parsing completed successfully");
|
||||
|
||||
return { success: true, data: debInfo };
|
||||
} catch (err) {
|
||||
logger.error({ err, debPath }, "[Submitter] Failed to parse deb file with exception");
|
||||
return {
|
||||
success: false,
|
||||
message: (err as Error)?.message || "解析deb文件失败",
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.handle("search-history-app", async (_event, pkgname: string, useMirror = false) => {
|
||||
try {
|
||||
const baseUrl = useMirror
|
||||
? "https://mirrors.sdu.edu.cn/spark-store"
|
||||
: "https://spk-json.spark-app.store";
|
||||
const storeArchs = ["store", "aarch64-store", "loong64-store"];
|
||||
const categories = [
|
||||
"chat",
|
||||
"development",
|
||||
"games",
|
||||
"image_graphics",
|
||||
"music",
|
||||
"network",
|
||||
"office",
|
||||
"others",
|
||||
"reading",
|
||||
"themes",
|
||||
"tools",
|
||||
"video",
|
||||
];
|
||||
const results: HistoryAppInfo[] = [];
|
||||
|
||||
logger.info("[Submitter] ============== SEARCH HISTORY APP START ==============");
|
||||
logger.info({ pkgname, useMirror, baseUrl, storeArchs, categories }, "[Submitter] Search parameters");
|
||||
|
||||
const allPromises: Promise<void>[] = [];
|
||||
|
||||
for (const arch of storeArchs) {
|
||||
for (const category of categories) {
|
||||
const url = `${baseUrl}/${arch}/${category}/${pkgname}/app.json`;
|
||||
logger.info({ arch, category, url }, "[Submitter] Starting search request");
|
||||
|
||||
const promise = fetch(url, {
|
||||
headers: { "User-Agent": getUserAgent() },
|
||||
})
|
||||
.then(async (response) => {
|
||||
logger.info({ arch, category, status: response.status }, "[Submitter] Fetch completed");
|
||||
|
||||
if (response.ok) {
|
||||
const json = await response.json();
|
||||
logger.info({ arch, category, rawJson: JSON.stringify(json, null, 2) }, "[Submitter] Response parsed");
|
||||
|
||||
const appPkgname = json?.pkgname || json?.Pkgname || json?.packageName || "";
|
||||
logger.info({ arch, category, appPkgname, searchPkgname: pkgname }, "[Submitter] Comparing pkgname");
|
||||
|
||||
if (appPkgname.toLowerCase() === pkgname.toLowerCase()) {
|
||||
logger.info({ arch, category, item: json }, "[Submitter] Found matching item");
|
||||
|
||||
let iconUrl = json.icons || json.icon || "";
|
||||
let imgs = json.imgUrls || json.imgs || json.img_urls || [];
|
||||
|
||||
if (typeof imgs === "string") {
|
||||
try {
|
||||
imgs = JSON.parse(imgs);
|
||||
logger.info({ arch, category, parsedImgsCount: Array.isArray(imgs) ? imgs.length : 0 }, "[Submitter] Parsed img_urls from string");
|
||||
} catch {
|
||||
imgs = [];
|
||||
logger.warn({ arch, category, imgsString: imgs }, "[Submitter] Failed to parse img_urls string");
|
||||
}
|
||||
}
|
||||
|
||||
if (iconUrl && typeof iconUrl === "string") {
|
||||
if (useMirror) {
|
||||
iconUrl = iconUrl.replace("spk-json.spark-app.store", "mirrors.sdu.edu.cn/spark-store");
|
||||
}
|
||||
}
|
||||
|
||||
if (Array.isArray(imgs)) {
|
||||
imgs = imgs.map((img: string) => {
|
||||
if (useMirror && typeof img === "string") {
|
||||
return img.replace("spk-json.spark-app.store", "mirrors.sdu.edu.cn/spark-store");
|
||||
}
|
||||
return img;
|
||||
});
|
||||
}
|
||||
|
||||
results.push({
|
||||
id: json.id || json.Id || 0,
|
||||
name: json.name || json.Name || "",
|
||||
pkgname: json.pkgname || json.Pkgname || "",
|
||||
version: json.version || json.Version || "",
|
||||
store: arch,
|
||||
author: json.author || json.Author || "",
|
||||
contributor: json.contributor || json.Contributor || "",
|
||||
website: json.website || json.Website || "",
|
||||
category: category,
|
||||
tags: json.tags || json.Tags || "",
|
||||
more: json.more || json.More || "",
|
||||
icon: iconUrl,
|
||||
imgs: imgs,
|
||||
});
|
||||
|
||||
logger.info({ arch, count: results.length }, "[Submitter] Added to results");
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
logger.warn({ arch, category, error }, "[Submitter] Request failed or exception caught");
|
||||
});
|
||||
|
||||
allPromises.push(promise);
|
||||
}
|
||||
}
|
||||
|
||||
await Promise.all(allPromises);
|
||||
|
||||
logger.info("[Submitter] ============== SEARCH COMPLETED ==============");
|
||||
logger.info({ totalResults: results.length, results }, "[Submitter] Search results");
|
||||
|
||||
return { success: true, data: results };
|
||||
} catch (err) {
|
||||
logger.error("[Submitter] ============== SEARCH FAILED ==============");
|
||||
logger.error({ errorType: (err as Error)?.name, errorMessage: (err as Error)?.message, errorStack: (err as Error)?.stack }, "[Submitter] Exception caught");
|
||||
return {
|
||||
success: false,
|
||||
message: (err as Error)?.message || "搜索历史信息失败",
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.handle("get-category-list", async () => {
|
||||
try {
|
||||
const apiUrl = "https://upload.deepinos.org.cn/api/index/getTypeList";
|
||||
logger.info("[Submitter] ============== GET CATEGORY LIST START ==============");
|
||||
logger.info({ apiUrl, userAgent: getUserAgent() }, "[Submitter] Request parameters");
|
||||
|
||||
const startTime = Date.now();
|
||||
const response = await fetch(apiUrl, {
|
||||
headers: { "User-Agent": getUserAgent() },
|
||||
});
|
||||
const endTime = Date.now();
|
||||
|
||||
logger.info({ status: response.status, statusText: response.statusText, duration: endTime - startTime }, "[Submitter] Fetch completed");
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
logger.error({ status: response.status, errorBody: errorText }, "[Submitter] Request failed");
|
||||
return { success: false, message: `获取分类列表失败 (${response.status})` };
|
||||
}
|
||||
|
||||
const json = await response.json();
|
||||
logger.info({ code: json?.code, msg: json?.msg, dataType: typeof json?.data, dataLength: json?.data?.length || "N/A", response: json }, "[Submitter] Response parsed");
|
||||
|
||||
return { success: true, data: json };
|
||||
} catch (err) {
|
||||
logger.error({ errorType: (err as Error)?.name, errorMessage: (err as Error)?.message, errorStack: (err as Error)?.stack }, "[Submitter] Exception caught");
|
||||
return {
|
||||
success: false,
|
||||
message: (err as Error)?.message || "获取分类列表失败",
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.handle("get-tags-list", async () => {
|
||||
try {
|
||||
const apiUrl = "https://upload.deepinos.org.cn/api/index/getTagsList";
|
||||
logger.info("[Submitter] ============== GET TAGS LIST START ==============");
|
||||
logger.info({ apiUrl, userAgent: getUserAgent() }, "[Submitter] Request parameters");
|
||||
|
||||
const startTime = Date.now();
|
||||
const response = await fetch(apiUrl, {
|
||||
headers: { "User-Agent": getUserAgent() },
|
||||
});
|
||||
const endTime = Date.now();
|
||||
|
||||
logger.info({ status: response.status, statusText: response.statusText, duration: endTime - startTime }, "[Submitter] Fetch completed");
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
logger.error({ status: response.status, errorBody: errorText }, "[Submitter] Request failed");
|
||||
return { success: false, message: `获取标签列表失败 (${response.status})` };
|
||||
}
|
||||
|
||||
const json = await response.json();
|
||||
logger.info({ code: json?.code, msg: json?.msg, dataType: typeof json?.data, dataLength: json?.data?.length || "N/A", response: json }, "[Submitter] Response parsed");
|
||||
|
||||
return { success: true, data: json };
|
||||
} catch (err) {
|
||||
logger.error({ errorType: (err as Error)?.name, errorMessage: (err as Error)?.message, errorStack: (err as Error)?.stack }, "[Submitter] Exception caught");
|
||||
return {
|
||||
success: false,
|
||||
message: (err as Error)?.message || "获取标签列表失败",
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
interface OssUploadMetadata {
|
||||
code: number;
|
||||
msg: string;
|
||||
data: {
|
||||
dir: string;
|
||||
host: string;
|
||||
ossAccessKeyId: string;
|
||||
policy: string;
|
||||
signature: string;
|
||||
};
|
||||
}
|
||||
|
||||
const categoryNameToIdMap: Record<string, number> = {
|
||||
"network": 3,
|
||||
"chat": 9,
|
||||
"music": 2,
|
||||
"video": 12,
|
||||
"image_graphics": 6,
|
||||
"games": 1,
|
||||
"office": 4,
|
||||
"reading": 8,
|
||||
"development": 7,
|
||||
"tools": 11,
|
||||
"themes": 10,
|
||||
"others": 5,
|
||||
};
|
||||
|
||||
function getCategoryIdByName(categoryName: string): number {
|
||||
return categoryNameToIdMap[categoryName];
|
||||
}
|
||||
|
||||
function generateUUID(): string {
|
||||
const hexChars = "0123456789abcdef";
|
||||
let uuid = "";
|
||||
for (let i = 0; i < 32; i++) {
|
||||
uuid += hexChars[Math.floor(Math.random() * 16)];
|
||||
}
|
||||
return uuid;
|
||||
}
|
||||
|
||||
function getUUIDFileNameSuggestIcoPic(filePath: string): string {
|
||||
const ext = path.extname(filePath).toLowerCase().replace(".", "");
|
||||
const uuid = generateUUID();
|
||||
return `${uuid}.${ext}`;
|
||||
}
|
||||
|
||||
function getUUIDFileNameSuggestDeb(_filePath: string): string {
|
||||
const uuid = generateUUID();
|
||||
return `${uuid}.deb`;
|
||||
}
|
||||
|
||||
async function getOssUploadMetadata(type: "icons" | "pic" | "deb"): Promise<OssUploadMetadata> {
|
||||
const startTime = Date.now();
|
||||
const pathMap: Record<string, string> = {
|
||||
icons: "upload_icons",
|
||||
pic: "upload_pic",
|
||||
deb: "upload_deb",
|
||||
};
|
||||
const url = `https://upload.deepinos.org.cn/api/index/${pathMap[type]}`;
|
||||
logger.info(`[Submitter] ============== GET OSS METADATA START (${type}) ==============`);
|
||||
logger.info({ url, timestamp: new Date().toISOString() }, `[Submitter] Getting OSS metadata for ${type}`);
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"User-Agent": getUserAgent(),
|
||||
},
|
||||
});
|
||||
|
||||
const duration = Date.now() - startTime;
|
||||
logger.info({ status: response.status, statusText: response.statusText, duration }, `[Submitter] OSS metadata response for ${type}`);
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
logger.error({ errorText }, `[Submitter] Failed to get OSS metadata for ${type}`);
|
||||
throw new Error(`获取 ${type} 上传签名失败: ${response.status} - ${errorText.substring(0, 200)}`);
|
||||
}
|
||||
|
||||
const responseText = await response.text();
|
||||
logger.info({ responseTextLength: responseText.length, responseText: responseText.substring(0, 1000) }, `[Submitter] Raw OSS metadata response for ${type}`);
|
||||
|
||||
let result: unknown;
|
||||
try {
|
||||
result = JSON.parse(responseText);
|
||||
logger.info({ resultType: typeof result, resultKeys: typeof result === "object" && result !== null ? Object.keys(result as object) : [] }, `[Submitter] Parsed OSS metadata result type for ${type}`);
|
||||
} catch (parseError) {
|
||||
logger.error({ parseError: (parseError as Error)?.message }, `[Submitter] Failed to parse OSS metadata response for ${type}`);
|
||||
throw new Error(`解析 ${type} 上传签名响应失败: ${(parseError as Error)?.message}`);
|
||||
}
|
||||
|
||||
if (typeof result !== "object" || result === null) {
|
||||
logger.error({ result }, `[Submitter] OSS metadata response is not an object for ${type}`);
|
||||
throw new Error(`${type} 上传签名响应格式错误`);
|
||||
}
|
||||
|
||||
const resultObj = result as Record<string, unknown>;
|
||||
if (resultObj.data === undefined || resultObj.data === null) {
|
||||
logger.error({ result }, `[Submitter] OSS metadata response data field is undefined for ${type}`);
|
||||
throw new Error(`${type} 上传签名响应缺少 data 字段`);
|
||||
}
|
||||
|
||||
const dataObj = resultObj.data as Record<string, unknown>;
|
||||
if (!dataObj.host || !dataObj.dir) {
|
||||
logger.error({ data: resultObj.data }, `[Submitter] OSS metadata response data missing host or dir for ${type}`);
|
||||
throw new Error(`${type} 上传签名响应 data 字段缺少 host 或 dir`);
|
||||
}
|
||||
|
||||
const ossMetadata: OssUploadMetadata = {
|
||||
code: Number(resultObj.code) || 0,
|
||||
msg: String(resultObj.msg || ""),
|
||||
data: {
|
||||
dir: String(dataObj.dir),
|
||||
host: String(dataObj.host),
|
||||
ossAccessKeyId: String(dataObj.OSSAccessKeyId || dataObj.ossAccessKeyId || dataObj.oss_access_key_id || ""),
|
||||
policy: String(dataObj.policy || ""),
|
||||
signature: String(dataObj.signature || ""),
|
||||
},
|
||||
};
|
||||
|
||||
logger.info(`[Submitter] ============== OSS METADATA RECEIVED (${type}) ==============`);
|
||||
logger.info({ code: ossMetadata.code, msg: ossMetadata.msg }, `[Submitter] OSS metadata result for ${type}`);
|
||||
logger.info({ host: ossMetadata.data.host, dir: ossMetadata.data.dir }, `[Submitter] OSS upload host and dir for ${type}`);
|
||||
logger.info({ ossAccessKeyIdLength: ossMetadata.data.ossAccessKeyId.length, policyLength: ossMetadata.data.policy.length, signatureLength: ossMetadata.data.signature.length }, `[Submitter] OSS credential lengths for ${type}`);
|
||||
|
||||
return ossMetadata;
|
||||
}
|
||||
|
||||
type UploadProgressCallback = (progress: number, fileType: string) => void;
|
||||
|
||||
async function uploadFileToOss(
|
||||
metadata: OssUploadMetadata,
|
||||
filePath: string,
|
||||
fileName: string,
|
||||
mimeType: string,
|
||||
fileType: string,
|
||||
progressCallback?: UploadProgressCallback
|
||||
): Promise<string> {
|
||||
const startTime = Date.now();
|
||||
const { host, dir, ossAccessKeyId, policy, signature } = metadata.data;
|
||||
const uploadUrl = host;
|
||||
const objectKey = `${dir}${fileName}`;
|
||||
|
||||
logger.info(`[Submitter] ============== UPLOAD FILE START (${fileType}) ==============`);
|
||||
logger.info({ uploadUrl, objectKey, filePath, fileName, mimeType, timestamp: new Date().toISOString() }, `[Submitter] Starting upload for ${fileType}`);
|
||||
|
||||
const fileStat = fs.statSync(filePath);
|
||||
const fileSize = fileStat.size;
|
||||
logger.info({ fileSize, fileSizeHuman: `${(fileSize / 1024 / 1024).toFixed(2)} MB` }, `[Submitter] File size for ${fileType}`);
|
||||
|
||||
const fileBuffer = fs.readFileSync(filePath);
|
||||
logger.info({ bufferSize: fileBuffer.length }, `[Submitter] File buffer ready for ${fileType}`);
|
||||
|
||||
const boundary = `----SparkStoreUploadBoundary${Date.now().toString(36)}`;
|
||||
const CRLF = Buffer.from("\r\n", "ascii");
|
||||
|
||||
const encodeField = (str: string) => Buffer.from(str, "utf8");
|
||||
|
||||
const headerBuffers: Buffer[] = [];
|
||||
headerBuffers.push(encodeField(`--${boundary}\r\n`));
|
||||
headerBuffers.push(encodeField(`Content-Disposition: form-data; name="key"\r\n\r\n`));
|
||||
headerBuffers.push(encodeField(objectKey));
|
||||
headerBuffers.push(CRLF);
|
||||
|
||||
headerBuffers.push(encodeField(`--${boundary}\r\n`));
|
||||
headerBuffers.push(encodeField(`Content-Disposition: form-data; name="ossAccessKeyId"\r\n\r\n`));
|
||||
headerBuffers.push(encodeField(ossAccessKeyId));
|
||||
headerBuffers.push(CRLF);
|
||||
|
||||
headerBuffers.push(encodeField(`--${boundary}\r\n`));
|
||||
headerBuffers.push(encodeField(`Content-Disposition: form-data; name="policy"\r\n\r\n`));
|
||||
headerBuffers.push(encodeField(policy));
|
||||
headerBuffers.push(CRLF);
|
||||
|
||||
headerBuffers.push(encodeField(`--${boundary}\r\n`));
|
||||
headerBuffers.push(encodeField(`Content-Disposition: form-data; name="signature"\r\n\r\n`));
|
||||
headerBuffers.push(encodeField(signature));
|
||||
headerBuffers.push(CRLF);
|
||||
|
||||
headerBuffers.push(encodeField(`--${boundary}\r\n`));
|
||||
headerBuffers.push(encodeField(`Content-Disposition: form-data; name="success_action_status"\r\n\r\n`));
|
||||
headerBuffers.push(encodeField("200"));
|
||||
headerBuffers.push(CRLF);
|
||||
|
||||
headerBuffers.push(encodeField(`--${boundary}\r\n`));
|
||||
headerBuffers.push(encodeField(`Content-Disposition: form-data; name="file"; filename="${fileName}"\r\n`));
|
||||
headerBuffers.push(encodeField(`Content-Type: ${mimeType}\r\n\r\n`));
|
||||
|
||||
const formHeaderBuffer = Buffer.concat(headerBuffers);
|
||||
const formFooterBuffer = Buffer.concat([CRLF, encodeField(`--${boundary}--\r\n`)]);
|
||||
const totalLength = formHeaderBuffer.length + fileBuffer.length + formFooterBuffer.length;
|
||||
|
||||
logger.info({ formHeaderLength: formHeaderBuffer.length, formFooterLength: formFooterBuffer.length, totalLength, fileSize }, `[Submitter] Form lengths for ${fileType}`);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const url = new URL(uploadUrl);
|
||||
const options: https.RequestOptions = {
|
||||
hostname: url.hostname,
|
||||
port: url.port ? parseInt(url.port) : 443,
|
||||
path: url.pathname + url.search,
|
||||
method: "POST",
|
||||
headers: {
|
||||
"User-Agent": getUserAgent(),
|
||||
"Content-Type": `multipart/form-data; boundary=${boundary}`,
|
||||
"Content-Length": totalLength,
|
||||
},
|
||||
};
|
||||
|
||||
logger.info(`[Submitter] ============== SENDING UPLOAD REQUEST (${fileType}) ==============`);
|
||||
|
||||
const req = https.request(options, (res) => {
|
||||
let responseData = "";
|
||||
res.on("data", (chunk) => {
|
||||
responseData += chunk;
|
||||
});
|
||||
res.on("end", () => {
|
||||
const duration = Date.now() - startTime;
|
||||
logger.info(`[Submitter] ============== UPLOAD RESPONSE RECEIVED (${fileType}) ==============`);
|
||||
logger.info({ status: res.statusCode, duration }, `[Submitter] Upload response for ${fileType}`);
|
||||
logger.info({ responseHeaders: res.headers }, `[Submitter] Response headers for ${fileType}`);
|
||||
logger.info({ responseBody: responseData.substring(0, 1000) }, `[Submitter] Response body for ${fileType}`);
|
||||
|
||||
if (res.statusCode !== 200) {
|
||||
logger.error({ errorText: responseData.substring(0, 500) }, `[Submitter] Upload failed for ${fileType}`);
|
||||
reject(new Error(`${fileType} 上传失败: ${res.statusCode} - ${responseData.substring(0, 500)}`));
|
||||
return;
|
||||
}
|
||||
|
||||
const finalUrl = `${host}${objectKey}`;
|
||||
logger.info({ finalUrl }, `[Submitter] ${fileType} upload successful, URL: ${finalUrl}`);
|
||||
resolve(finalUrl);
|
||||
});
|
||||
});
|
||||
|
||||
req.on("error", (err) => {
|
||||
logger.error({ err }, `[Submitter] Upload request error for ${fileType}`);
|
||||
reject(new Error(`${fileType} 上传失败: ${err.message}`));
|
||||
});
|
||||
|
||||
req.write(formHeaderBuffer);
|
||||
|
||||
let uploadedBytes = formHeaderBuffer.length;
|
||||
|
||||
const chunkSize = 1024 * 1024;
|
||||
for (let offset = 0; offset < fileBuffer.length; offset += chunkSize) {
|
||||
const chunk = fileBuffer.slice(offset, Math.min(offset + chunkSize, fileBuffer.length));
|
||||
req.write(chunk);
|
||||
uploadedBytes += chunk.length;
|
||||
|
||||
if (progressCallback) {
|
||||
const progress = Math.min((uploadedBytes / totalLength) * 100, 100);
|
||||
progressCallback(progress, fileType);
|
||||
}
|
||||
}
|
||||
|
||||
req.write(formFooterBuffer);
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
|
||||
ipcMain.handle("submit-app", async (event, formData: unknown) => {
|
||||
try {
|
||||
const startTime = Date.now();
|
||||
logger.info("[Submitter] ============== SUBMIT APP START ==============");
|
||||
logger.info({ timestamp: new Date().toISOString() }, "[Submitter] Submission started at");
|
||||
|
||||
if (typeof formData !== "object" || formData === null) {
|
||||
logger.error("[Submitter] Form data is not an object");
|
||||
return { success: false, message: "表单数据格式错误" };
|
||||
}
|
||||
|
||||
const dataObj = formData as Record<string, unknown>;
|
||||
logger.info("[Submitter] ============== FORM DATA RECEIVED ==============");
|
||||
logger.info({ name: dataObj.name }, "[Submitter] App name");
|
||||
logger.info({ pkgname: dataObj.pkgname }, "[Submitter] Package name");
|
||||
logger.info({ version: dataObj.version }, "[Submitter] Version");
|
||||
logger.info({ author: dataObj.author }, "[Submitter] Author");
|
||||
logger.info({ contributor: dataObj.contributor }, "[Submitter] Contributor");
|
||||
logger.info({ website: dataObj.website }, "[Submitter] Website");
|
||||
logger.info({ debFilePath: dataObj.debFilePath }, "[Submitter] Deb file path");
|
||||
logger.info({ iconPath: dataObj.iconPath }, "[Submitter] Icon path");
|
||||
logger.info({ category: dataObj.category }, "[Submitter] Category");
|
||||
logger.info({ tags: dataObj.tags }, "[Submitter] Tags");
|
||||
logger.info({ descriptionLength: typeof dataObj.description === "string" ? dataObj.description.length : 0 }, "[Submitter] Description length");
|
||||
logger.info({ screenshotsCount: Array.isArray(dataObj.screenshots) ? dataObj.screenshots.length : 0 }, "[Submitter] Screenshots count");
|
||||
|
||||
const debFilePath = String(dataObj.debFilePath || "");
|
||||
const iconPath = String(dataObj.iconPath || "");
|
||||
const screenshots = Array.isArray(dataObj.screenshots) ? dataObj.screenshots : [];
|
||||
|
||||
if (!debFilePath) {
|
||||
logger.error("[Submitter] Deb file path is empty");
|
||||
return { success: false, message: "请选择 deb 文件" };
|
||||
}
|
||||
|
||||
if (!fs.existsSync(debFilePath)) {
|
||||
logger.error({ debFilePath }, "[Submitter] Deb file does not exist");
|
||||
return { success: false, message: `deb 文件不存在: ${debFilePath}` };
|
||||
}
|
||||
|
||||
const sendUploadProgress = (step: string, progress: number, message: string) => {
|
||||
event.sender.send("submit-upload-progress", { step, progress, message });
|
||||
};
|
||||
|
||||
let iconUrl = "";
|
||||
if (iconPath) {
|
||||
logger.info("[Submitter] ============== STEP 1: UPLOAD ICON ==============");
|
||||
let iconFilePath = iconPath;
|
||||
|
||||
if (iconPath.startsWith("http://") || iconPath.startsWith("https://")) {
|
||||
logger.info({ iconPath }, "[Submitter] Icon is a remote URL, downloading first");
|
||||
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "spark-store-submitter-"));
|
||||
iconFilePath = path.join(tempDir, "icon.png");
|
||||
|
||||
try {
|
||||
const response = await fetch(iconPath);
|
||||
if (!response.ok) {
|
||||
throw new Error(`下载图标失败: ${response.status}`);
|
||||
}
|
||||
const blob = await response.blob();
|
||||
const buffer = Buffer.from(await blob.arrayBuffer());
|
||||
fs.writeFileSync(iconFilePath, buffer);
|
||||
logger.info({ iconFilePath, size: buffer.length }, "[Submitter] Icon downloaded successfully");
|
||||
} catch (err) {
|
||||
logger.error({ err, iconPath }, "[Submitter] Failed to download icon from URL");
|
||||
return { success: false, message: `下载图标失败: ${(err as Error).message}` };
|
||||
}
|
||||
}
|
||||
|
||||
if (fs.existsSync(iconFilePath)) {
|
||||
const iconMetadata = await getOssUploadMetadata("icons");
|
||||
const iconFileName = getUUIDFileNameSuggestIcoPic(iconFilePath);
|
||||
sendUploadProgress("icon", 0, "正在上传图标...");
|
||||
iconUrl = await uploadFileToOss(iconMetadata, iconFilePath, iconFileName, "image/png", "icon", (progress) => {
|
||||
sendUploadProgress("icon", progress, `正在上传图标... ${Math.floor(progress)}%`);
|
||||
});
|
||||
sendUploadProgress("icon", 100, "图标上传完成");
|
||||
logger.info({ iconUrl }, "[Submitter] Icon upload completed");
|
||||
|
||||
if (iconPath.startsWith("http://") || iconPath.startsWith("https://")) {
|
||||
fs.unlinkSync(iconFilePath);
|
||||
fs.rmdirSync(path.dirname(iconFilePath));
|
||||
}
|
||||
} else {
|
||||
logger.error({ iconFilePath }, "[Submitter] Icon file does not exist");
|
||||
return { success: false, message: `图标文件不存在: ${iconFilePath}` };
|
||||
}
|
||||
}
|
||||
|
||||
const screenshotUrls: string[] = [];
|
||||
for (let i = 0; i < screenshots.length; i++) {
|
||||
const screenshot = screenshots[i];
|
||||
logger.info({ index: i, screenshot }, "[Submitter] Processing screenshot");
|
||||
|
||||
if (typeof screenshot === "string") {
|
||||
logger.info(`[Submitter] ============== STEP 2: UPLOAD SCREENSHOT ${i + 1} ==============`);
|
||||
let screenshotFilePath = screenshot;
|
||||
|
||||
if (screenshot.startsWith("http://") || screenshot.startsWith("https://")) {
|
||||
logger.info({ screenshot }, "[Submitter] Screenshot is a remote URL, downloading first");
|
||||
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "spark-store-submitter-"));
|
||||
screenshotFilePath = path.join(tempDir, `screen_${i + 1}.png`);
|
||||
|
||||
try {
|
||||
const response = await fetch(screenshot);
|
||||
if (!response.ok) {
|
||||
throw new Error(`下载截图失败: ${response.status}`);
|
||||
}
|
||||
const blob = await response.blob();
|
||||
const buffer = Buffer.from(await blob.arrayBuffer());
|
||||
fs.writeFileSync(screenshotFilePath, buffer);
|
||||
logger.info({ screenshotFilePath, size: buffer.length }, "[Submitter] Screenshot downloaded successfully");
|
||||
} catch (err) {
|
||||
logger.error({ err, screenshot }, "[Submitter] Failed to download screenshot from URL");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (fs.existsSync(screenshotFilePath)) {
|
||||
const picMetadata = await getOssUploadMetadata("pic");
|
||||
const picFileName = getUUIDFileNameSuggestIcoPic(screenshotFilePath);
|
||||
sendUploadProgress(`screenshot-${i}`, 0, `正在上传截图 ${i + 1}...`);
|
||||
const picUrl = await uploadFileToOss(picMetadata, screenshotFilePath, picFileName, "image/png", `screenshot ${i + 1}`, (progress) => {
|
||||
sendUploadProgress(`screenshot-${i}`, progress, `正在上传截图 ${i + 1}... ${Math.floor(progress)}%`);
|
||||
});
|
||||
sendUploadProgress(`screenshot-${i}`, 100, `截图 ${i + 1} 上传完成`);
|
||||
screenshotUrls.push(picUrl);
|
||||
logger.info({ picUrl }, `[Submitter] Screenshot ${i + 1} upload completed`);
|
||||
|
||||
if (screenshot.startsWith("http://") || screenshot.startsWith("https://")) {
|
||||
fs.unlinkSync(screenshotFilePath);
|
||||
fs.rmdirSync(path.dirname(screenshotFilePath));
|
||||
}
|
||||
} else {
|
||||
logger.warn({ screenshotFilePath }, "[Submitter] Screenshot file does not exist, skipping");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("[Submitter] ============== STEP 3: UPLOAD DEB ==============");
|
||||
logger.info({ debFilePath, debFileName: getUUIDFileNameSuggestDeb(debFilePath) }, "[Submitter] Starting deb upload");
|
||||
const debMetadata = await getOssUploadMetadata("deb");
|
||||
const debFileName = getUUIDFileNameSuggestDeb(debFilePath);
|
||||
sendUploadProgress("deb", 0, "正在上传安装包...");
|
||||
const debUrl = await uploadFileToOss(debMetadata, debFilePath, debFileName, "application/vnd.debian.binary-package", "deb", (progress) => {
|
||||
sendUploadProgress("deb", progress, `正在上传安装包... ${Math.floor(progress)}%`);
|
||||
});
|
||||
sendUploadProgress("deb", 100, "安装包上传完成");
|
||||
logger.info("[Submitter] ============== DEB UPLOAD SUCCESSFUL ==============");
|
||||
logger.info({ debUrl, debFileName }, "[Submitter] Deb upload completed successfully");
|
||||
|
||||
logger.info("[Submitter] ============== STEP 4: SUBMIT APPLICATION ==============");
|
||||
|
||||
const debFileStat = fs.statSync(debFilePath);
|
||||
|
||||
const categoryName = String(dataObj.category || "");
|
||||
const categoryId = getCategoryIdByName(categoryName);
|
||||
logger.info({ categoryName, categoryId }, "[Submitter] Category name and ID");
|
||||
|
||||
const tagsString = String(dataObj.tags || "");
|
||||
const tagsArray = tagsString ? tagsString.split(";").map((t: string) => t.trim()).filter((t: string) => t) : [];
|
||||
logger.info({ tagsString, tagsArray }, "[Submitter] Tags conversion");
|
||||
|
||||
const submitData = {
|
||||
application_name: String(dataObj.pkgname || ""),
|
||||
application_name_zh: String(dataObj.name || ""),
|
||||
contributor: String(dataObj.contributor || ""),
|
||||
icons: iconUrl,
|
||||
size: debFileStat.size,
|
||||
file_name: path.basename(debFilePath).replace(/\s+/g, "_plus_"),
|
||||
website: String(dataObj.website || ""),
|
||||
version: String(dataObj.version || ""),
|
||||
more: String(dataObj.description || ""),
|
||||
type_id: categoryId,
|
||||
author: String(dataObj.author || ""),
|
||||
remark: (dataObj.remark as string || "") + " - (来自于投稿器_v" + getAppVersion() + ")",
|
||||
img_urls: screenshotUrls,
|
||||
deb_url: debUrl,
|
||||
mail: String(dataObj.mail || dataObj.contributor || ""),
|
||||
tags: tagsArray,
|
||||
};
|
||||
|
||||
logger.info("[Submitter] ============== VALIDATING SUBMISSION DATA ==============");
|
||||
const requiredFields = ["application_name", "application_name_zh", "contributor", "icons", "size", "file_name", "version", "type_id", "author", "deb_url"];
|
||||
const missingFields = requiredFields.filter((field) => !submitData[field as keyof typeof submitData]);
|
||||
if (missingFields.length > 0) {
|
||||
logger.error({ missingFields }, "[Submitter] Missing required fields");
|
||||
}
|
||||
|
||||
logger.info("[Submitter] ============== PREPARING SUBMISSION REQUEST ==============");
|
||||
logger.info({ submitData }, "[Submitter] Final submission data");
|
||||
|
||||
const submitterApiUrl = "https://upload.deepinos.org.cn/api/index/upload_application";
|
||||
logger.info({ submitterApiUrl }, "[Submitter] Submission API URL");
|
||||
|
||||
logger.info("[Submitter] ============== SENDING SUBMISSION REQUEST ==============");
|
||||
logger.info({ submitterApiUrl, timestamp: new Date().toISOString() }, "[Submitter] Submission request sent to API");
|
||||
|
||||
const response = await fetch(submitterApiUrl, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"User-Agent": getUserAgent(),
|
||||
},
|
||||
body: JSON.stringify(submitData),
|
||||
});
|
||||
|
||||
const requestDuration = Date.now() - startTime;
|
||||
logger.info("[Submitter] ============== SUBMISSION RESPONSE RECEIVED ==============");
|
||||
logger.info({ status: response.status, statusText: response.statusText }, "[Submitter] Submission response status");
|
||||
logger.info({ duration: requestDuration }, "[Submitter] Total submission duration (ms)");
|
||||
|
||||
const responseText = await response.text();
|
||||
logger.info({ responseTextLength: responseText.length }, "[Submitter] Submission response text length");
|
||||
|
||||
if (!response.ok) {
|
||||
logger.error("[Submitter] ============== SUBMISSION FAILED ==============");
|
||||
logger.error({ status: response.status, statusText: response.statusText }, "[Submitter] Submission failed with status");
|
||||
logger.error({ responseText: responseText.substring(0, 2000) }, "[Submitter] Submission API error response (full)");
|
||||
|
||||
let message = "提交失败";
|
||||
let apiResponse: unknown = null;
|
||||
|
||||
try {
|
||||
apiResponse = JSON.parse(responseText);
|
||||
logger.error({ apiResponse }, "[Submitter] Parsed API error response");
|
||||
} catch (parseError) {
|
||||
logger.warn({ parseError: (parseError as Error)?.message }, "[Submitter] Failed to parse error response as JSON");
|
||||
}
|
||||
|
||||
if (response.status === 521) {
|
||||
message = "服务器暂时不可用,请稍后重试";
|
||||
} else if (response.status === 400) {
|
||||
if (typeof apiResponse === "object" && apiResponse !== null) {
|
||||
const errorObj = apiResponse as Record<string, unknown>;
|
||||
message = String(errorObj.msg || errorObj.message || "请求参数错误");
|
||||
} else {
|
||||
message = responseText.substring(0, 200) || "请求参数错误";
|
||||
}
|
||||
} else if (response.status === 401) {
|
||||
message = "未授权,请登录后再试";
|
||||
} else if (response.status === 403) {
|
||||
message = "权限不足";
|
||||
} else if (response.status === 429) {
|
||||
message = "请求过于频繁,请稍后重试";
|
||||
} else {
|
||||
message = `提交失败 [${response.status}]: ${responseText.substring(0, 200)}`;
|
||||
}
|
||||
|
||||
logger.error({ finalMessage: message }, "[Submitter] Final error message to user");
|
||||
return { success: false, message, apiResponse };
|
||||
}
|
||||
|
||||
let result: unknown;
|
||||
try {
|
||||
result = JSON.parse(responseText);
|
||||
} catch (parseError) {
|
||||
logger.warn({ parseError: (parseError as Error)?.message }, "[Submitter] Failed to parse success response as JSON");
|
||||
result = responseText;
|
||||
}
|
||||
|
||||
logger.info("[Submitter] ============== SUBMISSION SUCCESSFUL ==============");
|
||||
logger.info({ result }, "[Submitter] Submission API response content");
|
||||
logger.info({ duration: requestDuration }, "[Submitter] Total duration (ms)");
|
||||
|
||||
return { success: true, data: result };
|
||||
} catch (err) {
|
||||
logger.error("[Submitter] ============== EXCEPTION CAUGHT ==============");
|
||||
logger.error({ errorType: (err as Error)?.name }, "[Submitter] Error type");
|
||||
logger.error({ errorMessage: (err as Error)?.message }, "[Submitter] Error message");
|
||||
logger.error({ errorStack: (err as Error)?.stack }, "[Submitter] Error stack");
|
||||
|
||||
return { success: false, message: (err as Error)?.message || "提交失败" };
|
||||
}
|
||||
});
|
||||
|
||||
// Register custom protocol handlers
|
||||
if (process.defaultApp) {
|
||||
if (process.argv.length >= 2) {
|
||||
|
||||
Generated
+14
-14
@@ -45,7 +45,7 @@
|
||||
"vite-plugin-electron-renderer": "^0.14.5",
|
||||
"vitest": "^4.1.4",
|
||||
"vue": "^3.4.21",
|
||||
"vue-tsc": "^3.2.4"
|
||||
"vue-tsc": "^3.3.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=22.12.0"
|
||||
@@ -3348,18 +3348,18 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@vue/language-core": {
|
||||
"version": "3.2.5",
|
||||
"resolved": "https://registry.npmjs.org/@vue/language-core/-/language-core-3.2.5.tgz",
|
||||
"integrity": "sha512-d3OIxN/+KRedeM5wQ6H6NIpwS3P5gC9nmyaHgBk+rO6dIsjY+tOh4UlPpiZbAh3YtLdCGEX4M16RmsBqPmJV+g==",
|
||||
"version": "3.3.5",
|
||||
"resolved": "https://registry.npmmirror.com/@vue/language-core/-/language-core-3.3.5.tgz",
|
||||
"integrity": "sha512-UkKu5nhX89fg4VhlG/FOeI10G3cj/7radKT/cy9BT4Q9qJmJlSTAc/dP63Xqs29aypN4f39xUV6PsLNk/dcD6g==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@volar/language-core": "2.4.28",
|
||||
"@vue/compiler-dom": "^3.5.0",
|
||||
"@vue/shared": "^3.5.0",
|
||||
"alien-signals": "^3.0.0",
|
||||
"alien-signals": "^3.2.0",
|
||||
"muggle-string": "^0.4.1",
|
||||
"path-browserify": "^1.0.1",
|
||||
"picomatch": "^4.0.2"
|
||||
"picomatch": "^4.0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/@vue/reactivity": {
|
||||
@@ -3494,9 +3494,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/alien-signals": {
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/alien-signals/-/alien-signals-3.1.2.tgz",
|
||||
"integrity": "sha512-d9dYqZTS90WLiU0I5c6DHj/HcKkF8ZyGN3G5x8wSbslulz70KOxaqCT0hQCo9KOyhVqzqGojvNdJXoTumZOtcw==",
|
||||
"version": "3.2.1",
|
||||
"resolved": "https://registry.npmmirror.com/alien-signals/-/alien-signals-3.2.1.tgz",
|
||||
"integrity": "sha512-I8FjmltrfnDFoZedi5CG8DghVYNhzb/Ijluz7tCSJH0xpd0484Kowhbb1XDYOxfJpU1p5wnM2X54dA+IfGyD1g==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/ansi-colors": {
|
||||
@@ -7636,7 +7636,7 @@
|
||||
},
|
||||
"node_modules/muggle-string": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/muggle-string/-/muggle-string-0.4.1.tgz",
|
||||
"resolved": "https://registry.npmmirror.com/muggle-string/-/muggle-string-0.4.1.tgz",
|
||||
"integrity": "sha512-VNTrAak/KhO2i8dqqnqnAHOa3cYBwXEZe9h+D5h/1ZqFSTEFHdM65lR7RoIqq3tBBYavsOXV84NoHXZ0AkPyqQ==",
|
||||
"dev": true
|
||||
},
|
||||
@@ -10088,13 +10088,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/vue-tsc": {
|
||||
"version": "3.2.5",
|
||||
"resolved": "https://registry.npmjs.org/vue-tsc/-/vue-tsc-3.2.5.tgz",
|
||||
"integrity": "sha512-/htfTCMluQ+P2FISGAooul8kO4JMheOTCbCy4M6dYnYYjqLe3BExZudAua6MSIKSFYQtFOYAll7XobYwcpokGA==",
|
||||
"version": "3.3.5",
|
||||
"resolved": "https://registry.npmmirror.com/vue-tsc/-/vue-tsc-3.3.5.tgz",
|
||||
"integrity": "sha512-Rzh/G2MmNlMSAMTiQEjDrsb4dgB/jbtEM47rVN2NtidF1dfb/q4w4QvpQBtW5+y3y5H27Hjh7deVwk+YB02fNg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@volar/typescript": "2.4.28",
|
||||
"@vue/language-core": "3.2.5"
|
||||
"@vue/language-core": "3.3.5"
|
||||
},
|
||||
"bin": {
|
||||
"vue-tsc": "bin/vue-tsc.js"
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "spark-store",
|
||||
"version": "5.1.1",
|
||||
"version": "5.2.0-alpha.1",
|
||||
"main": "dist-electron/main/index.js",
|
||||
"description": "Client for Spark App Store",
|
||||
"author": "elysia-best <elysia-best@simplelinux.cn.eu.org>",
|
||||
@@ -74,7 +74,7 @@
|
||||
"vite-plugin-electron-renderer": "^0.14.5",
|
||||
"vitest": "^4.1.4",
|
||||
"vue": "^3.4.21",
|
||||
"vue-tsc": "^3.2.4"
|
||||
"vue-tsc": "^3.3.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tailwindcss/vite": "^4.1.18",
|
||||
|
||||
+26
@@ -1,5 +1,7 @@
|
||||
<template>
|
||||
<SubmitterWindow v-if="isSubmitterView" />
|
||||
<div
|
||||
v-else
|
||||
class="flex min-h-screen flex-col bg-slate-50 text-slate-900 transition-colors duration-300 dark:bg-slate-950 dark:text-slate-100"
|
||||
>
|
||||
<WindowTitleBar />
|
||||
@@ -33,6 +35,7 @@
|
||||
@close="isSidebarOpen = false"
|
||||
@list="handleList"
|
||||
@update="handleUpdate"
|
||||
@submit="handleSubmit"
|
||||
@request-login="showLoginModal = true"
|
||||
@open-user-management="openUserManagement"
|
||||
@open-favorites="openFavoriteManagement"
|
||||
@@ -304,6 +307,7 @@ import FavoriteFolderManager from "./components/FavoriteFolderManager.vue";
|
||||
import UserManagementModal from "./components/UserManagementModal.vue";
|
||||
import ReviewUserProfileModal from "./components/ReviewUserProfileModal.vue";
|
||||
import WindowTitleBar from "./components/WindowTitleBar.vue";
|
||||
import SubmitterWindow from "./components/SubmitterWindow.vue";
|
||||
import {
|
||||
APM_STORE_BASE_URL,
|
||||
FLARUM_BASE_URL,
|
||||
@@ -434,6 +438,8 @@ const isDarkTheme = computed(() => {
|
||||
return themeMode.value === "dark";
|
||||
});
|
||||
|
||||
const isSubmitterView = ref(false);
|
||||
|
||||
const categories: Ref<Record<string, CategoryInfo>> = ref({});
|
||||
const apps: Ref<App[]> = ref([]);
|
||||
const tabCategories: Ref<Record<string, Record<string, CategoryInfo>>> = ref(
|
||||
@@ -1151,6 +1157,19 @@ const handleList = () => {
|
||||
openInstalledModal();
|
||||
};
|
||||
|
||||
const handleSubmit = async () => {
|
||||
try {
|
||||
const result = await window.ipcRenderer.invoke("launch-submitter");
|
||||
if (!result?.success) {
|
||||
logger.error(
|
||||
"Failed to launch submitter: " + (result?.message || "unknown error"),
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(`Failed to launch submitter: ${error}`);
|
||||
}
|
||||
};
|
||||
|
||||
const openUpdateModal = async () => {
|
||||
try {
|
||||
if (!effectiveStoreFilter.value) {
|
||||
@@ -2551,6 +2570,13 @@ onMounted(async () => {
|
||||
initTheme();
|
||||
updateCenterStore.bind();
|
||||
|
||||
const handleHashChange = () => {
|
||||
isSubmitterView.value = window.location.hash === "#submitter";
|
||||
};
|
||||
|
||||
handleHashChange();
|
||||
window.addEventListener("hashchange", handleHashChange);
|
||||
|
||||
try {
|
||||
systemInfo.value = await window.ipcRenderer.invoke("get-system-info");
|
||||
} catch (error: unknown) {
|
||||
|
||||
@@ -123,6 +123,14 @@
|
||||
<span class="sidebar-tab-icon"><i class="fas fa-sync-alt"></i></span>
|
||||
<span class="sidebar-tab-label">软件更新</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="sidebar-tab"
|
||||
@click="emitSidebarAction('submit')"
|
||||
>
|
||||
<span class="sidebar-tab-icon"><i class="fas fa-upload"></i></span>
|
||||
<span class="sidebar-tab-label">投稿应用</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -152,6 +160,7 @@ const emit = defineEmits<{
|
||||
(e: "close"): void;
|
||||
(e: "list"): void;
|
||||
(e: "update"): void;
|
||||
(e: "submit"): void;
|
||||
(e: "request-login"): void;
|
||||
(e: "open-user-management"): void;
|
||||
(e: "open-favorites"): void;
|
||||
@@ -227,10 +236,11 @@ const selectTab = (tab: string) => {
|
||||
emit("select-tab", tab);
|
||||
};
|
||||
|
||||
const emitSidebarAction = (action: "list" | "update") => {
|
||||
const emitSidebarAction = (action: "list" | "update" | "submit") => {
|
||||
showAccountMenu.value = false;
|
||||
if (action === "list") emit("list");
|
||||
else emit("update");
|
||||
else if (action === "update") emit("update");
|
||||
else emit("submit");
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
@@ -115,7 +115,9 @@
|
||||
<div v-if="lists.length > 0" class="space-y-6 mt-6">
|
||||
<section v-for="section in lists" :key="section.title">
|
||||
<div class="flex items-center justify-between">
|
||||
<h3 class="text-lg font-semibold text-slate-900 dark:text-slate-200">
|
||||
<h3
|
||||
class="text-lg font-semibold text-slate-900 dark:text-slate-200"
|
||||
>
|
||||
{{ section.title }}
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user