Skip to content

Commit

Permalink
refactor: refactor code structure
Browse files Browse the repository at this point in the history
  • Loading branch information
bitxeno committed Jun 22, 2024
1 parent dbf100d commit 599d333
Show file tree
Hide file tree
Showing 99 changed files with 610 additions and 800 deletions.
4 changes: 2 additions & 2 deletions .air.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ tmp_dir = "tmp"

[build]
# Just plain old shell command. You could use `make` as well.
cmd = "go build -tags dev -o ./tmp/main ."
cmd = "go build -o ./tmp/main ."
# Binary file yields from `cmd`.
bin = "tmp/main"
# Customize binary.
full_bin = "APP_ENV=dev APP_USER=air ./tmp/main server -vv"
# Watch these filename extensions.
include_ext = ["go", "tpl", "tmpl", "html", "vue", "js", "css", "woff", "ttf"]
# Ignore these filename extensions or directories.
exclude_dir = ["tmp", "libs", "vendor", "view"]
exclude_dir = ["tmp", "libs", "vendor", "view", "web/static"]
# Watch these directories if you specified.
include_dir = []
# Exclude files.
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
vendor/
tmp/
dist/
build/
/build
node_modules/
go-docker-skeleton
atvloadly
main
AltServerData/
atvloadly
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"json"
],
"i18n-ally.localesPaths": [
"view/src/locales"
"web/static/src/locales"
],
"i18n-ally.keystyle": "nested"
}
26 changes: 7 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,19 @@ RUN case ${TARGETARCH} in \
&& dpkg -i ./libimobiledevice_1.3.1-1_${PKG_ARCH}.deb \
&& dpkg -i ./usbmuxd2_1.0.0-1_${PKG_ARCH}.deb

# 安装anisette-server,用于模拟本机为MacBook
# 安装Sideloader
RUN case ${TARGETARCH} in \
"amd64") PKG_ARCH=x86_64 ;; \
"arm64") PKG_ARCH=aarch64 ;; \
esac \
&& cd /tmp \
&& wget https://github.com/Dadoum/Provision/releases/download/2.1.0/anisette-server-${PKG_ARCH} \
&& mv anisette-server-${PKG_ARCH} /usr/bin/anisette-server \
&& chmod +x /usr/bin/anisette-server

# 安装AltStore
RUN case ${TARGETARCH} in \
"amd64") PKG_ARCH=x86_64 ;; \
"arm64") PKG_ARCH=aarch64 ;; \
esac \
&& cd /tmp \
&& wget https://github.com/NyaMisty/AltServer-Linux/releases/download/v0.0.5/AltServer-${PKG_ARCH} \
&& mv AltServer-${PKG_ARCH} /usr/bin/AltServer \
&& chmod +x /usr/bin/AltServer
&& wget https://github.com/bitxeno/Sideloader/releases/download/1.0-alpha/sideloader-cli-${PKG_ARCH}-linux-gnu.tar.gz \
&& tar zxf sideloader-cli-${PKG_ARCH}-linux-gnu.tar.gz \
&& mv sideloader-cli-${PKG_ARCH}-linux-gnu /usr/bin/sideloader \
&& chmod +x /usr/bin/sideloader

# 安装tzdata支持更新时区
RUN DEBIAN_FRONTEND=noninteractive TZ=Asia/Shanghai apt-get -y install tzdata
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install tzdata

# 清空apt缓存和临时数据,减小镜像大小
RUN apt-get clean
Expand All @@ -66,21 +57,18 @@ RUN rm -rf /var/lib/lockdown && mkdir -p /data/lockdown && ln -s /data/lockdown


# 生成启动脚本
COPY ./doc/scripts/anisette-server /etc/init.d/anisette-server
RUN chmod +x /etc/init.d/anisette-server
COPY ./doc/scripts/usbmuxd /etc/init.d/usbmuxd
RUN chmod +x /etc/init.d/usbmuxd
RUN printf '#!/bin/sh \n\n\
mkdir -p /data/lockdown \n\
mkdir -p /data/AltServer \n\
mkdir -p /data/Sideloader \n\
if [ ! -f "/data/config.yaml" ]; then \n\
cp /doc/config.yaml /data/config.yaml \n\
fi \n\
/etc/init.d/usbmuxd start \n\
/etc/init.d/anisette-server start \n\
/usr/bin/%s server -p ${SERVICE_PORT:-80} -c /data/config.yaml \n\
\n\
Expand Down
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

<div align="center">

[![platform](https://img.shields.io/badge/platform-linux%20%7C%20openwrt-989898)](https://github.com/bitxeno/atvloadly/releases)
[![release](https://ghcr-badge.egpl.dev/bitxeno/atvloadly/latest_tag?label=docker%20latest)](https://github.com/bitxeno/atvloadly/pkgs/container/atvloadly)
[![image size](https://ghcr-badge.egpl.dev/bitxeno/atvloadly/size)](https://github.com/bitxeno/atvloadly/pkgs/container/atvloadly)
[![license](https://img.shields.io/github/license/bitxeno/atvloadly)](https://github.com/bitxeno/atvloadly/blob/master/LICENSE)
[![platform](https://img.shields.io/badge/platform-linux%20%7C%20openwrt-989898)](https://github.com/bitxeno/atvloadly/internal/releases)
[![release](https://ghcr-badge.egpl.dev/bitxeno/atvloadly/latest_tag?label=docker%20latest)](https://github.com/bitxeno/atvloadly/internal/pkgs/container/atvloadly)
[![image size](https://ghcr-badge.egpl.dev/bitxeno/atvloadly/size)](https://github.com/bitxeno/atvloadly/internal/pkgs/container/atvloadly)
[![license](https://img.shields.io/github/license/bitxeno/atvloadly)](https://github.com/bitxeno/atvloadly/internal/blob/master/LICENSE)
[![Telegram](https://img.shields.io/badge/telegram-2CA5E0?logo=telegram&logoColor=white)](https://t.me/atvloadly)

</div>
Expand All @@ -22,7 +22,7 @@ English | [中文](./README_cn.md)

> ⚠️ **Not supported on tvOS 17.0 and above systems.** ⚠️
atvloadly is a web service that supports sideloading app on Apple TV. It uses [AltServer](https://github.com/NyaMisty/AltServer-Linux) as the underlying technology for sideloading and automatically refreshes the app to ensure its long-term availability.
atvloadly is a web service that supports sideloading app on Apple TV. It uses [Sideloader](https://github.com/Dadoum/Sideloader) as the underlying technology for sideloading and automatically refreshes the app to ensure its long-term availability.

## Features

Expand Down Expand Up @@ -98,12 +98,16 @@ atvloadly is a web service that supports sideloading app on Apple TV. It uses [A
3. Can App-specific passwords be used for passwords? Is it more secure this way?

> AltServer currently does not support it.
> Sideloader currently does not support it.
4. 2 Step Verification
> When your Apple account has 2 factor verification enabled, you'll automatically be asked to verify your identity. If you have a trusted device configured for your account, then a code will appear on the device. If you don't have any devices configured, but have trusted a phone number, then a code will be sent to your phone.
> https://github.com/fastlane/fastlane/tree/master/spaceship#2-step-verification

## How to build

[>> wiki](https://github.com/bitxeno/atvloadly/wiki/How-to-build)
[>> wiki](https://github.com/bitxeno/atvloadly/internal/wiki/How-to-build)

## Donation

Expand Down
16 changes: 8 additions & 8 deletions README_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

<div align="center">

[![platform](https://img.shields.io/badge/platform-linux%20%7C%20openwrt-989898)](https://github.com/bitxeno/atvloadly/releases)
[![release](https://ghcr-badge.egpl.dev/bitxeno/atvloadly/latest_tag?label=docker%20latest)](https://github.com/bitxeno/atvloadly/pkgs/container/atvloadly)
[![image size](https://ghcr-badge.egpl.dev/bitxeno/atvloadly/size)](https://github.com/bitxeno/atvloadly/pkgs/container/atvloadly)
[![license](https://img.shields.io/github/license/bitxeno/atvloadly)](https://github.com/bitxeno/atvloadly/blob/master/LICENSE)
[![platform](https://img.shields.io/badge/platform-linux%20%7C%20openwrt-989898)](https://github.com/bitxeno/atvloadly/internal/releases)
[![release](https://ghcr-badge.egpl.dev/bitxeno/atvloadly/latest_tag?label=docker%20latest)](https://github.com/bitxeno/atvloadly/internal/pkgs/container/atvloadly)
[![image size](https://ghcr-badge.egpl.dev/bitxeno/atvloadly/size)](https://github.com/bitxeno/atvloadly/internal/pkgs/container/atvloadly)
[![license](https://img.shields.io/github/license/bitxeno/atvloadly)](https://github.com/bitxeno/atvloadly/internal/blob/master/LICENSE)
[![Telegram](https://img.shields.io/badge/telegram-2CA5E0?logo=telegram&logoColor=white)](https://t.me/atvloadly)


Expand All @@ -22,7 +22,7 @@

> ⚠️ **不支持 tvOS 17.0 以上系统** ⚠️
atvloadly 是一个支持在 AppleTV 上侧载应用的 web 服务。底层通过使用 [AltServer](https://github.com/NyaMisty/AltServer-Linux) 实现侧载,并会自动刷新 App 以保证其长期可用性。
atvloadly 是一个支持在 AppleTV 上侧载应用的 web 服务。底层通过使用 [Sideloader](https://github.com/Dadoum/Sideloader) 实现侧载,并会自动刷新 App 以保证其长期可用性。


## 主要功能
Expand Down Expand Up @@ -100,17 +100,17 @@ atvloadly 是一个支持在 AppleTV 上侧载应用的 web 服务。底层通
3、密码可以使用App-specific password吗,这样安全些

> AltServer 目前不支持
> Sideloader 目前不支持

## 推荐开源 App

[>> wiki](https://github.com/bitxeno/atvloadly/wiki/AppleTV-App)
[>> wiki](https://github.com/bitxeno/atvloadly/internal/wiki/AppleTV-App)


## 如何开发编译

[>> wiki](https://github.com/bitxeno/atvloadly/wiki/How-to-build)
[>> wiki](https://github.com/bitxeno/atvloadly/internal/wiki/How-to-build)

## 赞助

Expand Down
12 changes: 6 additions & 6 deletions internal/cmd/gen.go → cmd/gen/gen.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package cmd
package gen

import (
"github.com/urfave/cli/v2"
)

var (
genFlags = []cli.Flag{
flags = []cli.Flag{
&cli.StringFlag{
Name: "config",
Aliases: []string{"c"},
Expand All @@ -14,15 +14,15 @@ var (
},
}

genCommand = &cli.Command{
Command = &cli.Command{
Name: "gen",
Usage: "Generate example server code",
Flags: genFlags,
Action: generateAction,
Flags: flags,
Action: action,
}
)

func generateAction(c *cli.Context) error {
func action(c *cli.Context) error {
// if utils.Exists(app.ConfigFilePath) {
// fmt.Printf("Config has exist. >>> %s\n", app.ConfigFilePath)
// return nil
Expand Down
86 changes: 86 additions & 0 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package server

import (
"github.com/bitxeno/atvloadly/internal/app"
"github.com/bitxeno/atvloadly/internal/manager"
"github.com/bitxeno/atvloadly/internal/task"
"github.com/bitxeno/atvloadly/web"
"github.com/urfave/cli/v2"
)

var (
flags = []cli.Flag{
&cli.IntFlag{
Name: "port",
Aliases: []string{"p"},
Usage: "Define an alternate web server port",
},
&cli.StringFlag{
Name: "config",
Aliases: []string{"c"},
Usage: "Load configuration from `FILE`",
},
&cli.BoolFlag{
Name: "debug",
Aliases: []string{"vv"},
Usage: "Enable debug output",
Value: false,
},
&cli.BoolFlag{
Name: "verbose",
Aliases: []string{"vvv"},
Usage: "Enable verbose output",
Value: false,
},
}

Command = &cli.Command{
Name: "server",
Usage: "Run web server",
Flags: flags,
Action: action,
}
)

func action(c *cli.Context) error {
// init config
debug := false
if c.Bool("debug") || c.Bool("verbose") {
debug = true
}
conf, err := app.InitConfig(c.String("config"), debug)
if err != nil {
return err
}
if err = app.InitSettings(conf, debug); err != nil {
return err
}

// init logger
if c.Bool("debug") {
conf.Log.Level = "debug"
conf.Db.Debug = true
}
if c.Bool("verbose") {
conf.Log.Level = "trace"
conf.Db.Debug = true
}
if err := app.InitLogger(conf); err != nil {
return err
}

// init db
if err := app.InitDb(conf); err != nil {
return err
}

// start jobs
_ = task.ScheduleRefreshApps()
manager.StartDeviceManager()

port := conf.Server.Port
if c.Int("port") > 0 {
port = c.Int("port")
}
return web.Run(conf.Server.ListenAddr, port)
}
28 changes: 0 additions & 28 deletions config/app.go

This file was deleted.

9 changes: 0 additions & 9 deletions config/config.go

This file was deleted.

12 changes: 0 additions & 12 deletions fs_dev.go

This file was deleted.

20 changes: 0 additions & 20 deletions fs_prod.go

This file was deleted.

Loading

0 comments on commit 599d333

Please sign in to comment.