feat: windows app update

This commit is contained in:
Simon Ding
2025-04-29 18:54:56 +08:00
parent 3a73d0c33e
commit 5375f66018
14 changed files with 63 additions and 25 deletions

View File

@@ -2,5 +2,5 @@
windows:
@echo "Building for Windows..."
go build -tags c -ldflags="-X polaris/db.Version=$(git describe --tags --long)" -buildmode=c-shared -o ui/windows/libpolaris.dll ./cmd/binding
go build -tags lib -ldflags="-X polaris/db.Version=$(git describe --tags --long)" -buildmode=c-shared -o ui/windows/libpolaris.dll ./cmd/binding
cd ui && flutter build windows

View File

@@ -1,6 +1,9 @@
package db
import "polaris/ent/media"
import (
"polaris/ent/media"
"polaris/pkg/utils"
)
var (
Version = "undefined"
@@ -37,7 +40,10 @@ const (
const (
IndexerTorznabImpl = "torznab"
DataPath = "./data"
)
var (
DataPath = utils.GetUserDataDir()
ImgPath = DataPath + "/img"
LogPath = DataPath + "/logs"
)
@@ -49,7 +55,7 @@ const (
const DefaultNamingFormat = "{{.NameCN}} {{.NameEN}} {{if .Year}} ({{.Year}}) {{end}}"
//https://en.wikipedia.org/wiki/Video_file_format
// https://en.wikipedia.org/wiki/Video_file_format
var defaultAcceptedVideoFormats = []string{
".webm", ".mkv", ".flv", ".vob", ".ogv", ".ogg", ".drc", ".mng", ".avi", ".mts", ".m2ts", ".ts",
".mov", ".qt", ".wmv", ".yuv", ".rm", ".rmvb", ".viv", ".amv", ".mp4", ".m4p", ".m4v",

View File

@@ -3,6 +3,7 @@ package log
import (
"os"
"path/filepath"
"polaris/pkg/utils"
"strings"
"github.com/natefinch/lumberjack"
@@ -13,9 +14,6 @@ import (
var sugar *zap.SugaredLogger
var atom zap.AtomicLevel
const dataPath = "./data"
func init() {
InitLogger(false)
}
@@ -27,7 +25,7 @@ func InitLogger(toFile bool) {
w := zapcore.Lock(os.Stdout)
if toFile {
w = zapcore.AddSync(&lumberjack.Logger{
Filename: filepath.Join(dataPath, "logs", "polaris.log"),
Filename: filepath.Join(utils.GetUserDataDir(), "logs", "polaris.log"),
MaxSize: 50, // megabytes
MaxBackups: 3,
MaxAge: 30, // days

21
pkg/utils/dir_lib.go Normal file
View File

@@ -0,0 +1,21 @@
//go:build lib
package utils
import (
"os"
"path/filepath"
)
func GetUserDataDir() string {
d, err := os.UserHomeDir()
if err != nil {
panic(err)
}
d = filepath.Join(d, ".polaris")
if _, err := os.Stat(d); os.IsNotExist(err) {
os.MkdirAll(d, os.ModePerm)
}
return d
}

7
pkg/utils/dir_other.go Normal file
View File

@@ -0,0 +1,7 @@
//go:build !lib
package utils
func GetUserDataDir() string {
return "./data"
}

View File

@@ -247,7 +247,7 @@ func GetRealLinkAndHash(link string) (string, string, error) {
if err != nil {
return "", "", errors.Wrap(err, "parse response")
}
return link,info.HashInfoBytes().HexString(), nil
return link, info.HashInfoBytes().HexString(), nil
}
func Link2Magnet(link string) (string, error) {

View File

@@ -101,7 +101,7 @@ func (s *Server) setupRoutes() {
tv.POST("/tv/watchlist", HttpHandler(s.AddTv2Watchlist))
tv.GET("/tv/watchlist", HttpHandler(s.GetTvWatchlist))
tv.POST("/torrents", HttpHandler(s.SearchAvailableTorrents))
tv.POST("/torrents/download/", HttpHandler(s.DownloadTorrent))
tv.POST("/torrents/download", HttpHandler(s.DownloadTorrent))
tv.POST("/movie/watchlist", HttpHandler(s.AddMovie2Watchlist))
tv.GET("/movie/watchlist", HttpHandler(s.GetMovieWatchlist))
tv.GET("/record/:id", HttpHandler(s.GetMediaDetails))

View File

@@ -1,4 +1,4 @@
//go:build !c
//go:build !lib
package ui
import "embed"

View File

@@ -1,4 +1,4 @@
//go:build c
//go:build lib
package ui
import "embed"

View File

@@ -5,7 +5,6 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:ui/providers/server_response.dart';
import 'package:ui/widgets/utils.dart';
class APIs {
static int port = 8096;
@@ -32,7 +31,7 @@ class APIs {
static final allDownloadClientsUrl = "$_baseUrl/api/v1/downloader";
static final addDownloadClientUrl = "$_baseUrl/api/v1/downloader/add";
static final delDownloadClientUrl = "$_baseUrl/api/v1/downloader/del/";
static final storageUrl = "$_baseUrl/api/v1/storage/";
static final storageUrl = "$_baseUrl/api/v1/storage";
static final loginUrl = "$_baseUrl/api/login";
static final logoutUrl = "$_baseUrl/api/v1/setting/logout";
static final loginSettingUrl = "$_baseUrl/api/v1/setting/auth";
@@ -46,12 +45,12 @@ class APIs {
static final changeMonitoringUrl = "$_baseUrl/api/v1/setting/monitoring";
static final addImportlistUrl = "$_baseUrl/api/v1/importlist/add";
static final deleteImportlistUrl = "$_baseUrl/api/v1/importlist/delete";
static final getAllImportlists = "$_baseUrl/api/v1/importlist/";
static final getAllImportlists = "$_baseUrl/api/v1/importlist";
static final prowlarrUrl = "$_baseUrl/api/v1/setting/prowlarr";
static final notifierAllUrl = "$_baseUrl/api/v1/notifier/all";
static final notifierDeleteUrl = "$_baseUrl/api/v1/notifier/id/";
static final notifierAddUrl = "$_baseUrl/api/v1/notifier/add/";
static final notifierAddUrl = "$_baseUrl/api/v1/notifier/add";
static final tmdbImgBaseUrl = "$_baseUrl/api/v1/posters";
@@ -85,14 +84,21 @@ class APIs {
var dio = Dio();
dio.options.followRedirects = true;
dio.interceptors.add(InterceptorsWrapper(
onError: (error, handler) {
onError: (error, handler) async {
if (error.response?.statusCode != null &&
error.response?.statusCode! == 403) {
//not login
final context = navigatorKey.currentContext;
if (context != null) {
context.go('/login');
}
}
if (error.response?.statusCode == 307) {
final redirectUrl = error.response!.headers['Location']!.first;
final newResponse = await dio.get(_baseUrl+redirectUrl);
return handler.resolve(newResponse); // 返回修正后的响应
}
return handler.next(error);
},
));

View File

@@ -111,8 +111,8 @@ class Activity {
final String? saved;
final int? progress;
final int? size;
final double? seedRatio;
final double? uploadProgress;
final num? seedRatio;
final num? uploadProgress;
factory Activity.fromJson(Map<String, dynamic> json) {
return Activity(

View File

@@ -251,7 +251,7 @@ class MediaTorrentResource extends AutoDisposeFamilyAsyncNotifier<
"season": arg.seasonNumber,
"episode": arg.episodeNumber
});
final dio = await APIs.getDio();
final dio = APIs.getDio();
var resp = await dio.post(APIs.downloadTorrentUrl, data: data);
var rsp = ServerResponse.fromJson(resp.data);
if (rsp.code != 0) {

View File

@@ -315,7 +315,7 @@ class StorageSettingData extends AutoDisposeAsyncNotifier<List<Storage>> {
Future<void> deleteStorage(int id) async {
final dio = await APIs.getDio();
var resp = await dio.delete("${APIs.storageUrl}$id");
var resp = await dio.delete("${APIs.storageUrl}/$id");
var sp = ServerResponse.fromJson(resp.data);
if (sp.code != 0) {
throw sp.message;

View File

@@ -93,7 +93,7 @@ class _SystemPageState extends ConsumerState<SystemPage> {
]),
DataRow(cells: [
const DataCell(Text("更新监控列表")),
const DataCell(Text("小时")),
const DataCell(Text("20分钟")),
DataCell(IconButton(
icon: const Icon(Icons.not_started),
onPressed: () =>