Skip to content

Commit

Permalink
fix: 🐛 some bug
Browse files Browse the repository at this point in the history
'
  • Loading branch information
caorushizi committed May 25, 2024
1 parent 91b100b commit 84299ac
Show file tree
Hide file tree
Showing 13 changed files with 212 additions and 296 deletions.
Empty file removed packages/main/bin/win32/NO_UPDATE
Empty file.
Binary file removed packages/main/bin/win32/N_m3u8DL-CLI.exe
Binary file not shown.
Binary file added packages/main/bin/win32/N_m3u8DL-RE.exe
Binary file not shown.
4 changes: 1 addition & 3 deletions packages/main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-promise": "6.1.1",
"gulp": "^5.0.0",
"gulp-chmod": "^4.0.0",
"gulp-if": "^3.0.0",
"prebuild-install": "^7.1.1",
"prettier": "3.2.5",
"semver": "^7.5.4",
Expand All @@ -75,6 +73,6 @@
"node-pty": "^1.0.0",
"reflect-metadata": "^0.2.1",
"strip-ansi": "^7.1.0",
"typeorm": "^0.3.19"
"typeorm": "0.3.17"
}
}
2 changes: 1 addition & 1 deletion packages/main/scripts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function getConfig(): esbuild.BuildOptions {
process.env.NODE_ENV === "development"
? {
// 开发环境中二进制可执行文件的路径
__bin__: `"${mainResolve("bin", process.platform).replace(/\\/g, "\\\\")}"`,
__bin__: `"${mainResolve("app/bin").replace(/\\/g, "\\\\")}"`,
}
: {
...env,
Expand Down
56 changes: 36 additions & 20 deletions packages/main/scripts/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { deleteSync } from "del";
import { ElectronApp, mainResolve, Env, isMac, isLinux } from "./utils";
import { ElectronApp, mainResolve, Env, isWin } from "./utils";
import gulp from "gulp";
import chmod from "gulp-chmod";
import * as esbuild from "esbuild";
import consola from "consola";
import { browserOptions, nodeOptions, getReleaseConfig } from "./config";
import gulpIf from "gulp-if";
import semver from "semver";
import pkg from "../app/package.json";
import * as builder from "electron-builder";
import glob from "glob";
import path from "path";
import fs from "fs";

process.env.NODE_ENV = "development";

Expand All @@ -23,25 +24,40 @@ async function clean() {
]);
}

// function copySqlLite() {
// const path = "build/Release/better_sqlite3.node";
// const from = mainResolve("node_modules/better-sqlite3", path);
// const to = mainResolve("app/build/Release");
// return gulp.src(from).pipe(gulp.dest(to));
// }

function copyBin() {
return gulp
.src(mainResolve("bin", process.platform, "*"), {
ignore: [".gitignore", "Logs/**/*"],
})
.pipe(gulp.dest(mainResolve("app/bin")));
async function copyBin() {
const sourceDir = mainResolve("bin", process.platform);
const targetDir = mainResolve("app/bin");

// 获取源目录下的所有文件
const files = glob.sync(path.join(sourceDir, "*"));

// 遍历每个文件
for (const file of files) {
// 忽略 .gitignore 文件和 Logs 文件夹
if (file.endsWith(".gitignore") || file.includes("Logs")) {
continue;
}

// 计算目标文件的路径
const targetFile = path.join(targetDir, path.basename(file));
// 如果没有文件夹则创建文件夹
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir);
}

// 复制文件
fs.copyFileSync(file, targetFile);
}
}

function chmodBin() {
return gulp
.src(mainResolve("app/bin/*"))
.pipe(gulpIf(isMac || isLinux, chmod(0o777)));
async function chmodBin() {
// 遍历文件夹下的所有文件,将文件的权限设置为 777
if (isWin) return;

const files = glob.sync(mainResolve("app/bin/*"));
for (const file of files) {
fs.chmodSync(file, 0o777);
}
}

const copy = gulp.parallel(copyBin);
Expand Down
4 changes: 1 addition & 3 deletions packages/main/src/helper/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ export const PERSIST_WEBVIEW = "persist:webview";
export const db = resolve(workspace, "app.db");

// bin path
const downloaderBinName = isWin ? "N_m3u8DL-CLI" : "N_m3u8DL-RE";
export const ffmpegPath = resolveBin("ffmpeg");
export const biliDownloaderBin = resolveBin("BBDown");
export const m3u8DownloaderBin = resolveBin(downloaderBinName);
export const videoServerBin = resolveBin("server");
export const m3u8DownloaderBin = resolveBin("N_m3u8DL-RE");

// plugin path
export const pluginPath = resolveStatic("plugin/index.js");
Expand Down
12 changes: 6 additions & 6 deletions packages/main/src/repository/VideoRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ export default class VideoRepository {

async changeVideoStatus(id: number | number[], status: DownloadStatus) {
const ids = !Array.isArray(id) ? [id] : id;
return this.db.appDataSource
.createQueryBuilder()
.update(Video)
.set({ status })
.where({ id: In(ids) })
.execute();
const videoRepository = this.db.appDataSource.getRepository(Video);
const videos = await videoRepository.findBy({ id: In(ids) });
for (const video of videos) {
video.status = status;
}
await videoRepository.save(videos);
}

async changeVideoIsLive(id: number) {
Expand Down
34 changes: 1 addition & 33 deletions packages/main/src/services/DownloadService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,39 +49,7 @@ interface Schema {
const processList: Schema[] = [
{
type: "m3u8",
platform: [Platform.Windows],
bin: m3u8DownloaderBin,
args: {
url: {
argsName: null,
},
localDir: {
argsName: ["--workDir"],
},
name: {
argsName: ["--saveName"],
},
// headers: {
// argsName: ["--headers"],
// },
deleteSegments: {
argsName: ["--enableDelAfterDone"],
},
proxy: {
argsName: ["--proxyAddress"],
},
},
consoleReg: {
percent: "([\\d.]+)%",
speed: "([\\d.]+\\s[GMK]B/s)",
error: "ERROR",
start: "开始下载文件|开始录制",
isLive: "识别为直播流, 开始录制",
},
},
{
type: "m3u8",
platform: [Platform.MacOS, Platform.Linux],
platform: [Platform.MacOS, Platform.Linux, Platform.Windows],
bin: m3u8DownloaderBin,
args: {
url: {
Expand Down
112 changes: 56 additions & 56 deletions packages/renderer/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ConfigProvider, theme } from "antd";
import React, { FC, Suspense, lazy, useEffect } from "react";
import AppLayout from "./layout/App";
import { useDispatch } from "react-redux";
import { RouterProvider, createHashRouter } from "react-router-dom";
import { BrowserRouter, Route, Routes } from "react-router-dom";
import { DownloadFilter } from "./nodes/HomePage";
import { setAppStore, increase } from "./store";
import "dayjs/locale/zh-cn";
Expand All @@ -11,63 +10,11 @@ import "./App.scss";
import useElectron from "./hooks/electron";
import Loading from "./components/Loading";

const AppLayout = lazy(() => import("./layout/App"));
const HomePage = lazy(() => import("./nodes/HomePage"));
const SourceExtract = lazy(() => import("./nodes/SourceExtract"));
const SettingPage = lazy(() => import("./nodes/SettingPage"));

const router = createHashRouter([
{
path: "/",
element: <AppLayout />,
children: [
{
index: true,
element: (
<Suspense fallback={<Loading />}>
<HomePage />
</Suspense>
),
},
{
path: "done",
element: (
<Suspense fallback={<Loading />}>
<HomePage filter={DownloadFilter.done} />
</Suspense>
),
},
{
path: "source",
element: (
<Suspense fallback={<Loading />}>
<SourceExtract />
</Suspense>
),
},
{
path: "settings",
element: (
<Suspense fallback={<Loading />}>
<SettingPage />
</Suspense>
),
},
],
},
{
path: "/browser",
element: (
<Suspense fallback={<Loading />}>
<SourceExtract page={true} />
</Suspense>
),
},
{
path: "*",
element: <div>404</div>,
},
]);

function getAlgorithm(appTheme: "dark" | "light") {
return appTheme === "dark" ? theme.darkAlgorithm : theme.defaultAlgorithm;
}
Expand Down Expand Up @@ -125,7 +72,60 @@ const App: FC = () => {
componentSize="small"
theme={{ algorithm: getAlgorithm(appTheme) }}
>
<RouterProvider router={router} />
<BrowserRouter>
<Routes>
<Route
path="/"
element={
<Suspense fallback={<Loading />}>
<AppLayout />
</Suspense>
}
>
<Route
index
element={
<Suspense fallback={<Loading />}>
<HomePage />
</Suspense>
}
/>
<Route
path="done"
element={
<Suspense fallback={<Loading />}>
<HomePage filter={DownloadFilter.done} />
</Suspense>
}
/>
<Route
path="source"
element={
<Suspense fallback={<Loading />}>
<SourceExtract />
</Suspense>
}
/>
<Route
path="settings"
element={
<Suspense fallback={<Loading />}>
<SettingPage />
</Suspense>
}
/>
<Route path="*" element={<div>404</div>} />
</Route>
<Route
path="/browser"
element={
<Suspense fallback={<Loading />}>
<SourceExtract page={true} />
</Suspense>
}
/>
</Routes>
</BrowserRouter>
</ConfigProvider>
);
};
Expand Down
23 changes: 13 additions & 10 deletions packages/renderer/src/nodes/HomePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import {
import { useSelector } from "react-redux";
import { selectAppStore } from "../../store";
import DownloadFrom from "../../components/DownloadForm";
import dayjs from "dayjs";
import { Trans, useTranslation } from "react-i18next";
import Terminal from "../../components/Terminal";
import { moment } from "../../utils";

const { Text } = Typography;

Expand Down Expand Up @@ -60,7 +60,12 @@ const HomePage: FC<Props> = ({ filter = DownloadFilter.list }) => {
} = useElectron();
const appStore = useSelector(selectAppStore);
const { t } = useTranslation();
const { data, loading, pagination, refresh } = usePagination(
const {
data = { total: 0, list: [] },
loading,
pagination,
refresh,
} = usePagination(
({ current, pageSize }) => {
return getDownloadItems({
current,
Expand All @@ -84,7 +89,7 @@ const HomePage: FC<Props> = ({ filter = DownloadFilter.list }) => {
log: "",
});

const onDownloadProgress = (e: any, progress: DownloadProgress) => {
const onDownloadProgress = (e: unknown, progress: DownloadProgress) => {
setProgress((curProgress) => ({
...curProgress,
[progress.id]: progress,
Expand Down Expand Up @@ -411,9 +416,7 @@ const HomePage: FC<Props> = ({ filter = DownloadFilter.list }) => {
const items = batchList.split("\n").map((item: any) => {
let [url, name] = item.split(" ");
url = url ? url.trim() : "";
name = name
? name.trim()
: dayjs().format("YYYY-MM-DDTHH:mm:ssZ");
name = name ? name.trim() : moment();
return {
url,
name,
Expand All @@ -423,7 +426,7 @@ const HomePage: FC<Props> = ({ filter = DownloadFilter.list }) => {
await addDownloadItems(items);
} else {
await addDownloadItem({
name: values.name || dayjs().format("YYYY-MM-DDTHH:mm:ssZ"),
name: values.name || moment(),
url: values.url,
headers: values.headers,
type: DownloadType.m3u8,
Expand Down Expand Up @@ -464,7 +467,7 @@ const HomePage: FC<Props> = ({ filter = DownloadFilter.list }) => {
}}
rowKey="id"
rowSelection={rowSelection}
dataSource={data?.list || []}
dataSource={data.list || []}
tableAlertOptionRender={({ selectedRowKeys, onCleanSelected }) => {
if (selectedRowKeys.length === 0) {
return null;
Expand Down Expand Up @@ -496,11 +499,11 @@ const HomePage: FC<Props> = ({ filter = DownloadFilter.list }) => {
tableAlertRender={({ selectedRows }) => {
return (
<>
{data?.list.length !== 0 && (
{data.list.length !== 0 && (
<Button
type="link"
onClick={() => {
const list = data?.list || [];
const list = data.list || [];
const ids = list.map((item) => item.id || 0);
if (ids) {
setSelectedRowKeys(ids);
Expand Down
Loading

0 comments on commit 84299ac

Please sign in to comment.