mirror of
https://github.com/simon-ding/polaris.git
synced 2026-02-06 15:10:49 +08:00
feat: windows app update
This commit is contained in:
2
Makefile
2
Makefile
@@ -2,5 +2,5 @@
|
|||||||
|
|
||||||
windows:
|
windows:
|
||||||
@echo "Building for 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
|
cd ui && flutter build windows
|
||||||
10
db/const.go
10
db/const.go
@@ -1,6 +1,9 @@
|
|||||||
package db
|
package db
|
||||||
|
|
||||||
import "polaris/ent/media"
|
import (
|
||||||
|
"polaris/ent/media"
|
||||||
|
"polaris/pkg/utils"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Version = "undefined"
|
Version = "undefined"
|
||||||
@@ -37,7 +40,10 @@ const (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
IndexerTorznabImpl = "torznab"
|
IndexerTorznabImpl = "torznab"
|
||||||
DataPath = "./data"
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
DataPath = utils.GetUserDataDir()
|
||||||
ImgPath = DataPath + "/img"
|
ImgPath = DataPath + "/img"
|
||||||
LogPath = DataPath + "/logs"
|
LogPath = DataPath + "/logs"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package log
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"polaris/pkg/utils"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/natefinch/lumberjack"
|
"github.com/natefinch/lumberjack"
|
||||||
@@ -13,9 +14,6 @@ import (
|
|||||||
var sugar *zap.SugaredLogger
|
var sugar *zap.SugaredLogger
|
||||||
var atom zap.AtomicLevel
|
var atom zap.AtomicLevel
|
||||||
|
|
||||||
const dataPath = "./data"
|
|
||||||
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
InitLogger(false)
|
InitLogger(false)
|
||||||
}
|
}
|
||||||
@@ -27,7 +25,7 @@ func InitLogger(toFile bool) {
|
|||||||
w := zapcore.Lock(os.Stdout)
|
w := zapcore.Lock(os.Stdout)
|
||||||
if toFile {
|
if toFile {
|
||||||
w = zapcore.AddSync(&lumberjack.Logger{
|
w = zapcore.AddSync(&lumberjack.Logger{
|
||||||
Filename: filepath.Join(dataPath, "logs", "polaris.log"),
|
Filename: filepath.Join(utils.GetUserDataDir(), "logs", "polaris.log"),
|
||||||
MaxSize: 50, // megabytes
|
MaxSize: 50, // megabytes
|
||||||
MaxBackups: 3,
|
MaxBackups: 3,
|
||||||
MaxAge: 30, // days
|
MaxAge: 30, // days
|
||||||
|
|||||||
21
pkg/utils/dir_lib.go
Normal file
21
pkg/utils/dir_lib.go
Normal 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
7
pkg/utils/dir_other.go
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
//go:build !lib
|
||||||
|
|
||||||
|
package utils
|
||||||
|
|
||||||
|
func GetUserDataDir() string {
|
||||||
|
return "./data"
|
||||||
|
}
|
||||||
@@ -101,7 +101,7 @@ func (s *Server) setupRoutes() {
|
|||||||
tv.POST("/tv/watchlist", HttpHandler(s.AddTv2Watchlist))
|
tv.POST("/tv/watchlist", HttpHandler(s.AddTv2Watchlist))
|
||||||
tv.GET("/tv/watchlist", HttpHandler(s.GetTvWatchlist))
|
tv.GET("/tv/watchlist", HttpHandler(s.GetTvWatchlist))
|
||||||
tv.POST("/torrents", HttpHandler(s.SearchAvailableTorrents))
|
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.POST("/movie/watchlist", HttpHandler(s.AddMovie2Watchlist))
|
||||||
tv.GET("/movie/watchlist", HttpHandler(s.GetMovieWatchlist))
|
tv.GET("/movie/watchlist", HttpHandler(s.GetMovieWatchlist))
|
||||||
tv.GET("/record/:id", HttpHandler(s.GetMediaDetails))
|
tv.GET("/record/:id", HttpHandler(s.GetMediaDetails))
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//go:build !c
|
//go:build !lib
|
||||||
package ui
|
package ui
|
||||||
|
|
||||||
import "embed"
|
import "embed"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//go:build c
|
//go:build lib
|
||||||
package ui
|
package ui
|
||||||
|
|
||||||
import "embed"
|
import "embed"
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import 'package:flutter/foundation.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:ui/providers/server_response.dart';
|
import 'package:ui/providers/server_response.dart';
|
||||||
import 'package:ui/widgets/utils.dart';
|
|
||||||
|
|
||||||
class APIs {
|
class APIs {
|
||||||
static int port = 8096;
|
static int port = 8096;
|
||||||
@@ -32,7 +31,7 @@ class APIs {
|
|||||||
static final allDownloadClientsUrl = "$_baseUrl/api/v1/downloader";
|
static final allDownloadClientsUrl = "$_baseUrl/api/v1/downloader";
|
||||||
static final addDownloadClientUrl = "$_baseUrl/api/v1/downloader/add";
|
static final addDownloadClientUrl = "$_baseUrl/api/v1/downloader/add";
|
||||||
static final delDownloadClientUrl = "$_baseUrl/api/v1/downloader/del/";
|
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 loginUrl = "$_baseUrl/api/login";
|
||||||
static final logoutUrl = "$_baseUrl/api/v1/setting/logout";
|
static final logoutUrl = "$_baseUrl/api/v1/setting/logout";
|
||||||
static final loginSettingUrl = "$_baseUrl/api/v1/setting/auth";
|
static final loginSettingUrl = "$_baseUrl/api/v1/setting/auth";
|
||||||
@@ -46,12 +45,12 @@ class APIs {
|
|||||||
static final changeMonitoringUrl = "$_baseUrl/api/v1/setting/monitoring";
|
static final changeMonitoringUrl = "$_baseUrl/api/v1/setting/monitoring";
|
||||||
static final addImportlistUrl = "$_baseUrl/api/v1/importlist/add";
|
static final addImportlistUrl = "$_baseUrl/api/v1/importlist/add";
|
||||||
static final deleteImportlistUrl = "$_baseUrl/api/v1/importlist/delete";
|
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 prowlarrUrl = "$_baseUrl/api/v1/setting/prowlarr";
|
||||||
|
|
||||||
static final notifierAllUrl = "$_baseUrl/api/v1/notifier/all";
|
static final notifierAllUrl = "$_baseUrl/api/v1/notifier/all";
|
||||||
static final notifierDeleteUrl = "$_baseUrl/api/v1/notifier/id/";
|
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";
|
static final tmdbImgBaseUrl = "$_baseUrl/api/v1/posters";
|
||||||
|
|
||||||
@@ -85,14 +84,21 @@ class APIs {
|
|||||||
var dio = Dio();
|
var dio = Dio();
|
||||||
dio.options.followRedirects = true;
|
dio.options.followRedirects = true;
|
||||||
dio.interceptors.add(InterceptorsWrapper(
|
dio.interceptors.add(InterceptorsWrapper(
|
||||||
onError: (error, handler) {
|
onError: (error, handler) async {
|
||||||
if (error.response?.statusCode != null &&
|
if (error.response?.statusCode != null &&
|
||||||
error.response?.statusCode! == 403) {
|
error.response?.statusCode! == 403) {
|
||||||
|
//not login
|
||||||
final context = navigatorKey.currentContext;
|
final context = navigatorKey.currentContext;
|
||||||
if (context != null) {
|
if (context != null) {
|
||||||
context.go('/login');
|
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);
|
return handler.next(error);
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -111,8 +111,8 @@ class Activity {
|
|||||||
final String? saved;
|
final String? saved;
|
||||||
final int? progress;
|
final int? progress;
|
||||||
final int? size;
|
final int? size;
|
||||||
final double? seedRatio;
|
final num? seedRatio;
|
||||||
final double? uploadProgress;
|
final num? uploadProgress;
|
||||||
|
|
||||||
factory Activity.fromJson(Map<String, dynamic> json) {
|
factory Activity.fromJson(Map<String, dynamic> json) {
|
||||||
return Activity(
|
return Activity(
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ class MediaTorrentResource extends AutoDisposeFamilyAsyncNotifier<
|
|||||||
"season": arg.seasonNumber,
|
"season": arg.seasonNumber,
|
||||||
"episode": arg.episodeNumber
|
"episode": arg.episodeNumber
|
||||||
});
|
});
|
||||||
final dio = await APIs.getDio();
|
final dio = APIs.getDio();
|
||||||
var resp = await dio.post(APIs.downloadTorrentUrl, data: data);
|
var resp = await dio.post(APIs.downloadTorrentUrl, data: data);
|
||||||
var rsp = ServerResponse.fromJson(resp.data);
|
var rsp = ServerResponse.fromJson(resp.data);
|
||||||
if (rsp.code != 0) {
|
if (rsp.code != 0) {
|
||||||
|
|||||||
@@ -315,7 +315,7 @@ class StorageSettingData extends AutoDisposeAsyncNotifier<List<Storage>> {
|
|||||||
|
|
||||||
Future<void> deleteStorage(int id) async {
|
Future<void> deleteStorage(int id) async {
|
||||||
final dio = await APIs.getDio();
|
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);
|
var sp = ServerResponse.fromJson(resp.data);
|
||||||
if (sp.code != 0) {
|
if (sp.code != 0) {
|
||||||
throw sp.message;
|
throw sp.message;
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ class _SystemPageState extends ConsumerState<SystemPage> {
|
|||||||
]),
|
]),
|
||||||
DataRow(cells: [
|
DataRow(cells: [
|
||||||
const DataCell(Text("更新监控列表")),
|
const DataCell(Text("更新监控列表")),
|
||||||
const DataCell(Text("每小时")),
|
const DataCell(Text("每20分钟")),
|
||||||
DataCell(IconButton(
|
DataCell(IconButton(
|
||||||
icon: const Icon(Icons.not_started),
|
icon: const Icon(Icons.not_started),
|
||||||
onPressed: () =>
|
onPressed: () =>
|
||||||
|
|||||||
Reference in New Issue
Block a user