mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-09 01:50:30 +00:00
ci: build web
This commit is contained in:
1 parent
ff4e6f448c
commit
bf8e24a6af
13 files changed
+140
-74
No files matched your search
@@ -25,39 +25,39 @@ jobs:
|
||||
id: create_release
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
build-cli:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [ release ]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: '^1.19'
|
||||
cache: true
|
||||
- name: Build
|
||||
env:
|
||||
VERSION: ${{ needs.release.outputs.tag_name }}
|
||||
run: |
|
||||
mkdir -p dist/zip
|
||||
goos_arr=(windows darwin linux)
|
||||
goarch_arr=(386 amd64 arm64)
|
||||
export CGO_ENABLED=0
|
||||
for goos in "${goos_arr[@]}"; do
|
||||
for goarch in "${goarch_arr[@]}"; do
|
||||
dir="dist/gopeed-$VERSION-$goos-$goarch/"
|
||||
(GOOS=$goos GOARCH=$goarch go build -tags nosqlite -ldflags="-s -w" -o $dir github.com/monkeyWie/gopeed/cmd/gopeed \
|
||||
&& cd $dir \
|
||||
&& zip -r ../zip/gopeed-cli-$VERSION-$goos-$goarch.zip * \
|
||||
&& cd ../..) \
|
||||
|| true
|
||||
done
|
||||
done
|
||||
- name: Upload
|
||||
uses: shogo82148/actions-upload-release-asset@v1
|
||||
with:
|
||||
upload_url: ${{ needs.release.outputs.upload_url }}
|
||||
asset_path: dist/zip/*
|
||||
overwrite: true
|
||||
# build-cli:
|
||||
# runs-on: ubuntu-latest
|
||||
# needs: [ release ]
|
||||
# steps:
|
||||
# - uses: actions/checkout@v3
|
||||
# - uses: actions/setup-go@v3
|
||||
# with:
|
||||
# go-version: '^1.19'
|
||||
# cache: true
|
||||
# - name: Build
|
||||
# env:
|
||||
# VERSION: ${{ needs.release.outputs.tag_name }}
|
||||
# run: |
|
||||
# mkdir -p dist/zip
|
||||
# goos_arr=(windows darwin linux)
|
||||
# goarch_arr=(386 amd64 arm64)
|
||||
# export CGO_ENABLED=0
|
||||
# for goos in "${goos_arr[@]}"; do
|
||||
# for goarch in "${goarch_arr[@]}"; do
|
||||
# dir="dist/gopeed-$VERSION-$goos-$goarch/"
|
||||
# (GOOS=$goos GOARCH=$goarch go build -tags nosqlite -ldflags="-s -w" -o $dir github.com/monkeyWie/gopeed/cmd/gopeed \
|
||||
# && cd $dir \
|
||||
# && zip -r ../zip/gopeed-cli-$VERSION-$goos-$goarch.zip * \
|
||||
# && cd ../..) \
|
||||
# || true
|
||||
# done
|
||||
# done
|
||||
# - name: Upload
|
||||
# uses: shogo82148/actions-upload-release-asset@v1
|
||||
# with:
|
||||
# upload_url: ${{ needs.release.outputs.upload_url }}
|
||||
# asset_path: dist/zip/*
|
||||
# overwrite: true
|
||||
build-macos-arm64-lib:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [ release ]
|
||||
@@ -163,7 +163,7 @@ jobs:
|
||||
mkdir ui/flutter/android/app/libs
|
||||
go install golang.org/x/mobile/cmd/gomobile@latest
|
||||
gomobile init
|
||||
gomobile bind -ldflags="-w -s" -o ui/flutter/android/app/libs/libgopeed.aar -target=android -androidapi 19 -javapkg=com.gopeed github.com/monkeyWie/gopeed/bind/mobile
|
||||
gomobile bind -tags nosqlite -ldflags="-w -s" -o ui/flutter/android/app/libs/libgopeed.aar -target=android -androidapi 19 -javapkg=com.gopeed github.com/monkeyWie/gopeed/bind/mobile
|
||||
cd ui/flutter
|
||||
flutter build apk
|
||||
mkdir dist
|
||||
@@ -174,3 +174,42 @@ jobs:
|
||||
upload_url: ${{ needs.release.outputs.upload_url }}
|
||||
asset_path: ui/flutter/dist/*
|
||||
overwrite: true
|
||||
build-web:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [ release ]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: '^1.19'
|
||||
cache: true
|
||||
- uses: subosito/flutter-action@v2
|
||||
- name: Build
|
||||
env:
|
||||
VERSION: ${{ needs.release.outputs.tag_name }}
|
||||
run: |
|
||||
cd ui/flutter
|
||||
flutter build web
|
||||
cd ../../
|
||||
cp -r ui/flutter/build/web cmd/web/dist
|
||||
mkdir -p dist/zip
|
||||
goos_arr=(windows darwin linux)
|
||||
goarch_arr=(386 amd64 arm64)
|
||||
export CGO_ENABLED=0
|
||||
for goos in "${goos_arr[@]}"; do
|
||||
for goarch in "${goarch_arr[@]}"; do
|
||||
dir="dist/gopeed-$VERSION-$goos-$goarch/"
|
||||
(GOOS=$goos GOARCH=$goarch go build -tags nosqlite -ldflags="-s -w" -o $dir github.com/monkeyWie/gopeed/cmd/web \
|
||||
&& cd $dir \
|
||||
&& rename 's/^web/gopeed/' * \
|
||||
&& zip -r ../zip/gopeed-web-$VERSION-$goos-$goarch.zip * \
|
||||
&& cd ../..) \
|
||||
|| true
|
||||
done
|
||||
done
|
||||
- name: Upload
|
||||
uses: shogo82148/actions-upload-release-asset@v1
|
||||
with:
|
||||
upload_url: ${{ needs.release.outputs.upload_url }}
|
||||
asset_path: dist/zip/*
|
||||
overwrite: true
|
||||
+3
-1
@@ -22,4 +22,6 @@ bin/
|
||||
*.data
|
||||
*.db
|
||||
|
||||
.DS_Store
|
||||
.DS_Store
|
||||
|
||||
dist/
|
||||
File renamed without changes.
File renamed without changes.
@@ -1,16 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/monkeyWie/gopeed/pkg/rest"
|
||||
"github.com/monkeyWie/gopeed/pkg/rest/model"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := rest.StartSync(&model.StartConfig{
|
||||
Network: "tcp",
|
||||
Address: "127.0.0.1:9999",
|
||||
Storage: model.StorageMem,
|
||||
}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
_______ ______ .______ _______ _______ _______
|
||||
/ _____| / __ \ | _ \ | ____|| ____|| \
|
||||
| | __ | | | | | |_) | | |__ | |__ | .--. |
|
||||
| | |_ | | | | | | ___/ | __| | __| | | | |
|
||||
| |__| | | `--' | | | | |____ | |____ | '--' |
|
||||
\______| \______/ | _| |_______||_______||_______/
|
||||
@@ -0,0 +1,39 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"github.com/monkeyWie/gopeed/pkg/rest"
|
||||
"github.com/monkeyWie/gopeed/pkg/rest/model"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
//go:embed banner.txt
|
||||
var banner string
|
||||
|
||||
//go:embed dist/*
|
||||
var dist embed.FS
|
||||
|
||||
func main() {
|
||||
sub, err := fs.Sub(dist, "dist")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cfg := &model.StartConfig{
|
||||
Network: "tcp",
|
||||
Address: "127.0.0.1:9999",
|
||||
Storage: model.StorageMem,
|
||||
WebEnable: true,
|
||||
WebFS: sub,
|
||||
}
|
||||
fmt.Println(banner)
|
||||
srv, listener, err := rest.BuildServer(cfg)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("Server start success on http://%s\n", listener.Addr().String())
|
||||
if err := srv.Serve(listener); err != nil && err != http.ErrServerClosed {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
@@ -11,11 +12,10 @@ type Controller interface {
|
||||
}
|
||||
|
||||
type DefaultController struct {
|
||||
Files map[string]*os.File
|
||||
}
|
||||
|
||||
func NewController() *DefaultController {
|
||||
return &DefaultController{Files: make(map[string]*os.File)}
|
||||
return &DefaultController{}
|
||||
}
|
||||
|
||||
func (c *DefaultController) Touch(name string, size int64) (file *os.File, err error) {
|
||||
@@ -24,15 +24,15 @@ func (c *DefaultController) Touch(name string, size int64) (file *os.File, err e
|
||||
return
|
||||
}
|
||||
file, err = os.Create(name)
|
||||
if err != nil && !errors.Is(err, os.ErrExist) {
|
||||
return
|
||||
}
|
||||
if size > 0 {
|
||||
err = os.Truncate(name, size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
c.Files[name] = file
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package model
|
||||
|
||||
import "io/fs"
|
||||
|
||||
type Storage string
|
||||
|
||||
const (
|
||||
@@ -13,6 +15,9 @@ type StartConfig struct {
|
||||
Storage Storage `json:"storage"`
|
||||
StorageDir string `json:"storageDir"`
|
||||
RefreshInterval int `json:"refreshInterval"`
|
||||
|
||||
WebEnable bool
|
||||
WebFS fs.FS
|
||||
}
|
||||
|
||||
func (cfg *StartConfig) Init() *StartConfig {
|
||||
|
||||
+5
-13
@@ -19,7 +19,7 @@ var (
|
||||
)
|
||||
|
||||
func Start(startCfg *model.StartConfig) (int, error) {
|
||||
srv, listener, err := buildServer(startCfg)
|
||||
srv, listener, err := BuildServer(startCfg)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -38,17 +38,6 @@ func Start(startCfg *model.StartConfig) (int, error) {
|
||||
return port, nil
|
||||
}
|
||||
|
||||
func StartSync(startCfg *model.StartConfig) error {
|
||||
srv, listener, err := buildServer(startCfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := srv.Serve(listener); err != nil && err != http.ErrServerClosed {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Stop() {
|
||||
if srv != nil {
|
||||
if err := srv.Shutdown(context.TODO()); err != nil {
|
||||
@@ -62,7 +51,7 @@ func Stop() {
|
||||
}
|
||||
}
|
||||
|
||||
func buildServer(startCfg *model.StartConfig) (*http.Server, net.Listener, error) {
|
||||
func BuildServer(startCfg *model.StartConfig) (*http.Server, net.Listener, error) {
|
||||
if startCfg == nil {
|
||||
startCfg = &model.StartConfig{}
|
||||
}
|
||||
@@ -104,6 +93,9 @@ func buildServer(startCfg *model.StartConfig) (*http.Server, net.Listener, error
|
||||
r.Methods(http.MethodGet).Path("/api/v1/tasks").HandlerFunc(GetTasks)
|
||||
r.Methods(http.MethodGet).Path("/api/v1/config").HandlerFunc(GetConfig)
|
||||
r.Methods(http.MethodPut).Path("/api/v1/config").HandlerFunc(PutConfig)
|
||||
if startCfg.WebEnable {
|
||||
r.PathPrefix("/").Handler(http.FileServer(http.FS(startCfg.WebFS)))
|
||||
}
|
||||
|
||||
srv = &http.Server{Handler: handlers.CORS(
|
||||
handlers.AllowedHeaders([]string{"X-Requested-With", "Content-Type", "Authorization"}),
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
/build/
|
||||
|
||||
# Web related
|
||||
lib/generated_plugin_registrant.dart
|
||||
|
||||
# Symbolication related
|
||||
app.*.symbols
|
||||
@@ -47,4 +46,4 @@ app.*.map.json
|
||||
android/app/libs/libgopeed.aar
|
||||
android/app/libs/libgopeed-sources.jar
|
||||
macos/Frameworks/libgopeed.h
|
||||
macos/Frameworks/libgopeed.dylib
|
||||
macos/Frameworks/libgopeed.dylib
|
||||
@@ -5,7 +5,8 @@
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||
|
||||
<application android:requestLegacyExternalStorage="true"
|
||||
<application
|
||||
android:requestLegacyExternalStorage="true"
|
||||
android:name="${applicationName}"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="gopeed">
|
||||
|
||||
@@ -114,8 +114,6 @@ class Item extends StatelessWidget {
|
||||
list.add(IconButton(
|
||||
icon: const Icon(Icons.folder_open),
|
||||
onPressed: () async {
|
||||
print(Util.buildAbsPath(task.opts.path, task.res.files[0].path,
|
||||
task.res.files[0].name));
|
||||
final file = File(Util.buildAbsPath(task.opts.path,
|
||||
task.res.files[0].path, task.res.files[0].name));
|
||||
await launchUrl(file.parent.uri);
|
||||
|
||||
Reference in new issue
Block a user