├── .github └── workflows │ ├── release.yml │ └── release_docker.yml ├── .gitignore ├── Dockerfile ├── README.md ├── api ├── auth │ ├── auth.go │ └── token.go ├── controllers │ ├── controllerAliOpen.go │ ├── controllerApp.go │ ├── controllerBelongsToCollections.go │ ├── controllerCastItems.go │ ├── controllerConfig.go │ ├── controllerCrewItems.go │ ├── controllerEpisodes.go │ ├── controllerErrFiles.go │ ├── controllerFile.go │ ├── controllerGallerys.go │ ├── controllerGenres.go │ ├── controllerHearts.go │ ├── controllerLastEpisodeToAirs.go │ ├── controllerNetworkss.go │ ├── controllerNextEpisodeToAirs.go │ ├── controllerPlayeds.go │ ├── controllerProductionCompanies.go │ ├── controllerProductionCountries.go │ ├── controllerSeasons.go │ ├── controllerSpokenLanguages.go │ ├── controllerStars.go │ ├── controllerTheCredits.go │ ├── controllerTheMovies.go │ ├── controllerThePersons.go │ ├── controllerTheSeasons.go │ ├── controllerTheTvs.go │ ├── controllerUsers.go │ └── controllerWorks.go ├── crons │ └── cron.go ├── database │ └── db.go ├── middleware │ └── cors.go ├── models │ ├── AddData.go │ ├── AppApi.go │ ├── Claim.go │ ├── Config.go │ ├── ErrFile.go │ ├── Gallery.go │ ├── Heart.go │ ├── Played.go │ ├── Star.go │ ├── The.go │ ├── TheCredit.go │ ├── TheMovie.go │ ├── ThePerson.go │ ├── TheSeason.go │ ├── TheTv.go │ ├── User.go │ └── Work.go ├── repository │ ├── crud │ │ ├── repositoryBelongsToCollectionsCrud.go │ │ ├── repositoryCastItemsCrud.go │ │ ├── repositoryCrewItemsCrud.go │ │ ├── repositoryEpisodesCrud.go │ │ ├── repositoryErrFilesCrud.go │ │ ├── repositoryGallerysCrud.go │ │ ├── repositoryGenresCrud.go │ │ ├── repositoryHeartsCrud.go │ │ ├── repositoryLastEpisodeToAirsCrud.go │ │ ├── repositoryNetworkssCrud.go │ │ ├── repositoryNextEpisodeToAirsCrud.go │ │ ├── repositoryPlayedsCrud.go │ │ ├── repositoryProductionCompaniesCrud.go │ │ ├── repositoryProductionCountriesCrud.go │ │ ├── repositorySeasonsCrud.go │ │ ├── repositorySpokenLanguagesCrud.go │ │ ├── repositoryStarsCrud.go │ │ ├── repositoryTheCreditsCrud.go │ │ ├── repositoryTheMoviesCrud.go │ │ ├── repositoryThePersonsCrud.go │ │ ├── repositoryTheSeasonsCrud.go │ │ ├── repositoryTheTvsCrud.go │ │ ├── repositoryUsersCrud.go │ │ └── repositoryWorksCrud.go │ ├── repositoryBelongsToCollections.go │ ├── repositoryCastItems.go │ ├── repositoryCrewItems.go │ ├── repositoryEpisodes.go │ ├── repositoryErrFiles.go │ ├── repositoryGallerys.go │ ├── repositoryGenres.go │ ├── repositoryHearts.go │ ├── repositoryLastEpisodeToAirs.go │ ├── repositoryNetworkss.go │ ├── repositoryNextEpisodeToAirs.go │ ├── repositoryPlayeds.go │ ├── repositoryProductionCompanies.go │ ├── repositoryProductionCountries.go │ ├── repositorySeasons.go │ ├── repositorySpokenLanguages.go │ ├── repositoryStars.go │ ├── repositoryTheCredits.go │ ├── repositoryTheMovies.go │ ├── repositoryThePersons.go │ ├── repositoryTheSeasons.go │ ├── repositoryTheTvs.go │ ├── repositoryUsers.go │ └── repositoryWorks.go ├── security │ └── password.go ├── server.go ├── service │ └── service.go └── utils │ ├── cache │ └── cache.go │ ├── channels │ └── channels.go │ ├── dir │ └── dir.go │ ├── extract │ └── extract.go │ ├── gpool │ └── gpool.go │ └── tools │ └── tools.go ├── auto └── load.go ├── build.sh ├── config.env ├── config └── config.go ├── docker-compose.yml ├── docker └── rootfs │ └── etc │ └── s6-overlay │ └── s6-rc.d │ ├── init-config │ ├── run │ ├── type │ └── up │ ├── svc-onelist │ ├── dependencies.d │ │ └── init-config │ ├── finish │ ├── run │ └── type │ └── user │ └── contents.d │ ├── init-config │ └── svc-onelist ├── docs ├── docker_conpose_install.md ├── docker_install.md └── imgs │ ├── 01.png │ ├── 02.png │ ├── 03.png │ ├── wx.png │ └── zfb.jpg ├── go.mod ├── go.sum ├── initconfig └── initconfig.go ├── main.go ├── plugins ├── alist │ ├── alist.go │ └── mode.go ├── thedb │ ├── download.go │ ├── model.go │ └── thedb.go └── watch │ ├── watch.go │ └── work.go ├── public ├── README.md └── public.go └── wrapper ├── zcc-arm64 └── zcxx-arm64 /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: release 2 | 3 | on: 4 | release: 5 | types: [ published ] 6 | 7 | jobs: 8 | release: 9 | strategy: 10 | matrix: 11 | platform: [ ubuntu-latest ] 12 | go-version: [ 1.19 ] 13 | name: Release 14 | runs-on: ${{ matrix.platform }} 15 | steps: 16 | - name: prerelease 17 | uses: irongut/EditRelease@v1.2.0 18 | with: 19 | token: ${{ secrets.MY_TOKEN }} 20 | id: ${{ github.event.release.id }} 21 | prerelease: true 22 | 23 | - name: Setup Go 24 | uses: actions/setup-go@v3 25 | with: 26 | go-version: ${{ matrix.go-version }} 27 | 28 | - name: Checkout 29 | uses: actions/checkout@v3 30 | with: 31 | fetch-depth: 0 32 | 33 | - name: Install musl-tools 34 | run: | 35 | set -ex 36 | sudo apt-get update 37 | sudo apt-get install -y musl-tools 38 | 39 | - name: Install dependencies 40 | run: | 41 | sudo snap install zig --classic --beta 42 | docker pull crazymax/xgo:latest 43 | go install github.com/crazy-max/xgo@latest 44 | sudo apt install upx 45 | 46 | - name: Build 47 | run: | 48 | bash build.sh release 49 | 50 | - name: prerelease 51 | uses: irongut/EditRelease@v1.2.0 52 | with: 53 | token: ${{ secrets.MY_TOKEN }} 54 | id: ${{ github.event.release.id }} 55 | prerelease: false 56 | 57 | - name: Release 58 | uses: softprops/action-gh-release@v1 59 | with: 60 | files: build/compress/* -------------------------------------------------------------------------------- /.github/workflows/release_docker.yml: -------------------------------------------------------------------------------- 1 | name: release_docker 2 | 3 | on: 4 | release: 5 | types: [ published ] 6 | 7 | jobs: 8 | release_docker: 9 | name: Release Docker 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout 13 | uses: actions/checkout@v3 14 | 15 | - name: Docker meta 16 | id: meta 17 | uses: docker/metadata-action@v4 18 | with: 19 | images: ${{ secrets.DOCKER_USERNAME }}/onelist 20 | 21 | - name: Set up QEMU 22 | uses: docker/setup-qemu-action@v2 23 | 24 | - name: Set up Docker Buildx 25 | uses: docker/setup-buildx-action@v2 26 | 27 | - name: Login DockerHub 28 | uses: docker/login-action@v2 29 | with: 30 | username: ${{ secrets.DOCKER_USERNAME }} 31 | password: ${{ secrets.DOCKER_PASSWORD }} 32 | 33 | - name: Build and push 34 | uses: docker/build-push-action@v4 35 | with: 36 | context: . 37 | file: Dockerfile 38 | platforms: | 39 | linux/386 40 | linux/amd64 41 | linux/arm64/v8 42 | linux/arm/v7 43 | linux/arm/v6 44 | linux/s390x 45 | push: true 46 | tags: ${{ steps.meta.outputs.tags }} 47 | labels: ${{ steps.meta.outputs.labels }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | images 2 | *.db 3 | *.exe 4 | public/dist -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.18 AS Build 2 | 3 | RUN apk add --no-cache bash curl gcc git go musl-dev 4 | WORKDIR /build 5 | COPY --chmod=755 . /build 6 | RUN bash build.sh release docker 7 | 8 | FROM alpine:3.18 9 | 10 | LABEL MAINTAINER="ddsrem@163.com" 11 | 12 | ENV S6_SERVICES_GRACETIME=30000 \ 13 | S6_KILL_GRACETIME=60000 \ 14 | S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0 \ 15 | S6_SYNC_DISKS=1 \ 16 | LANG=C.UTF-8 \ 17 | PS1="\[\e[32m\][\[\e[m\]\[\e[36m\]\u \[\e[m\]\[\e[37m\]@ \[\e[m\]\[\e[34m\]\h\[\e[m\]\[\e[32m\]]\[\e[m\] \[\e[37;35m\]in\[\e[m\] \[\e[33m\]\w\[\e[m\] \[\e[32m\][\[\e[m\]\[\e[37m\]\d\[\e[m\] \[\e[m\]\[\e[37m\]\t\[\e[m\]\[\e[32m\]]\[\e[m\] \n\[\e[1;31m\]$ \[\e[0m\]" \ 18 | TZ=Asia/Shanghai \ 19 | PUID=911 \ 20 | PGID=911 \ 21 | GIN_MODE=release 22 | 23 | RUN apk add --no-cache \ 24 | tzdata \ 25 | bash \ 26 | s6-overlay \ 27 | ca-certificates && \ 28 | rm -rf /var/cache/apk/* 29 | 30 | COPY --chmod=755 ./docker/rootfs / 31 | COPY --chmod=755 --from=Build /build/bin/onelist /app/onelist 32 | 33 | WORKDIR /config 34 | 35 | ENTRYPOINT [ "/init" ] 36 | 37 | EXPOSE 5245 38 | VOLUME [ "/config" ] 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # onelist 2 | 一个类似emby的专注于刮削alist聚合网盘形成影视媒体库的程序。 3 | 4 | ![](./docs/imgs/01.png) 5 | 6 | ### 主要解决以下痛点: 7 | 8 | * alist挂载云盘后能在网页端看视频,却没有分类,没有海报墙 9 | 10 | * 使用webdav挂载本地后,用jellyfin或者emby刮削会下载视频截取封面导致封号 11 | 12 | * 用jellyfin或者emby之类,没有大带宽公网ip,在外难以访问 13 | 14 | ### 常见问题汇总: 15 | * 比如你的alist是这样"[https://pan.alist.com/阿里云盘/电影](https://pan.alist.com/阿里云盘/电影)",你在新建alist类型影库时候域名应该输入"https://pan.alist.com",不要有多余字符,在这个影库下挂载电影目录时候输入"/阿里云盘/电影" 16 | * 刮削成功无法播放,先确认alist使用最新版,且需要alist后台关闭"签名所有功能",还有要确认是否是浏览器不支持的编码,这种可以调用外部浏览器播放 17 | 18 | 19 | ### 多种安装方式,推荐docker安装: 20 | 21 | --- 22 | [docker安装](./docs/docker_install.md) | [docker-compose方式安装](./docs/docker_conpose_install.md) 23 | 24 | --- 25 | 26 | 手动安装教程:https://www.bilibili.com/video/BV15M41177LN 27 | ## 1.程序下载 28 | 可以在github发布页下载已经编译好的二进制文件 29 | 30 | 使用前必看,程序采用themoviedb作为刮削的资源库,推荐使用国外主机,否则你需要修改hosts文件。 31 | ``` 32 | 99.84.251.12 api.themoviedb.org 33 | 99.84.251.19 api.themoviedb.org 34 | 99.84.251.67 api.themoviedb.org 35 | 99.84.251.108 api.themoviedb.org 36 | 156.146.56.162 image.tmdb.org 37 | 108.138.246.49 image.tmdb.org 38 | ``` 39 | ## 2.下载后先初始化配置文件 40 | 41 | 输入`./onelist -run config`命令,便会生成配置文件config.env 42 | 修改完config.env配置文件后,运行`onelist -run server`便可启动项目,运行`onelist -run admin`可查看管理员账户! 43 | 44 | config.env 45 | ``` 46 | # 服务设置 47 | # 注意要改为未被占用的端口 48 | API_PORT=5245 49 | FaviconicoUrl=https://wework.qpic.cn/wwpic/818353_fizV30xbQCGPQRP_1677394564/0 50 | API_SECRET=fRVvjcNd11gYGI85StVaeCtPVSmJTRRE 51 | 52 | # Env有两种模式,Debug及Release,主要用在数据库为mysql时候,需要注意修改Env环境和mysql密码对应 53 | Env=Debug 54 | 55 | # 管理员账户设置,用于初始化管理员账户 56 | UserEmail=xxxx.@qq.com 57 | UserPassword=xxxxx 58 | 59 | # 数据库设置 60 | DB_DRIVER=sqlite 61 | DB_USER=root 62 | DbName=onelist 63 | 64 | # 如果上面DB_DRIVER类型为mysql,就需要正确填下以下参数 65 | DB_PASSWORD_Debug=123456 66 | DB_PASSWORD_Release=123456 67 | 68 | # TheMovieDb Key 69 | # 在https://www.themoviedb.org网站申请 70 | KeyDb=22f10ca52f109158ac7fe064ebbcf697 71 | ``` 72 | ## 3.运行程序 73 | 74 | ``` 75 | # 先运行,查看有无错误 76 | ./onelist -run server 77 | 78 | 注意:如果提示权限问题,可以先授权文件chmod 777 onelist 79 | 80 | # 如果想后台一直保持运行,可用以下命令 81 | nohup ./onelist -run server >/dev/null 2>&1 & 82 | ``` 83 | ## 4.登录 84 | 访问你的`ip:端口`就可以进入管理后台了(记得防火墙放行该端口) 85 | ## 5.添加媒体库 86 | ![](./docs/imgs/02.png) 87 | 88 | 1.对应输入媒体库名字,比如电影,类型选择movie 89 | 90 | 2.封面图片可以暂时不填 91 | 92 | 3.填写alist相关信息,这个主要用于程序查询你alist中文件,根据文件名进行刮削 93 | 94 | ## 6.挂载资源,新建完毕后,添加挂载目录。 95 | ![](./docs/images/03.png) 96 | 97 | 挂载的目录中文件必须满足下面这种命名方式 98 | ``` 99 | 电影就按电影名称 100 | 101 | 电视同一部美剧,所有季可以分开或者放在不同子目录,但是文件名一定得满足以下格式 102 | 权力的游戏S01E01.mp4 103 | 权力的游戏S01E02.mp4 104 | 权力的游戏S01E03.mp4 105 | ``` 106 | 填写比如`/阿里2号/电影01组`即可,可以选择是否自动刮削,用于你网盘有新文件,程序自动给你添加进影库, 107 | 108 | 点击创建后反应比较慢,是因为程序去遍历你的alist文件了,稍微等下 109 | 110 | > 注意:添加挂载目录只能选择你建立媒体库中采用的alist相关目录,要与alist域名一致 111 | > 112 | ## 7.创建后点击刷新就可以看到刮削进度了 113 | 114 | 可以进入错误文件中查看 115 | ### 交流群: 116 | > 群名称: 117 | onelist 118 | > QQ群 号: 119 | 765592050 120 | 121 | 122 | 感谢您的关注!开源不易,需要开发者们的不断努力和付出。如果您觉得我的项目对您有所帮助,希望能够支持我继续改进和维护这个项目,您可以考虑打赏我一杯咖啡的钱。 123 | 您的支持将是我继续前进的动力,让我能够更加专注地投入到开源社区中,让我的项目变得更加完善和有用。如果您决定打赏我,可以通过以下方式: 124 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 |
微信支付宝
微信支付宝
-------------------------------------------------------------------------------- /api/auth/auth.go: -------------------------------------------------------------------------------- 1 | package auth 2 | 3 | import ( 4 | "errors" 5 | 6 | "github.com/msterzhang/onelist/api/security" 7 | "github.com/msterzhang/onelist/api/utils/channels" 8 | 9 | "github.com/msterzhang/onelist/api/models" 10 | 11 | "github.com/msterzhang/onelist/api/database" 12 | 13 | "gorm.io/gorm" 14 | ) 15 | 16 | // SignIn method 17 | func Login(email, password string) (models.User, string, error) { 18 | user := models.User{} 19 | var err error 20 | var db *gorm.DB 21 | done := make(chan bool) 22 | go func(ch chan<- bool) { 23 | defer close(ch) 24 | db = database.NewDb() 25 | if err != nil { 26 | ch <- false 27 | return 28 | } 29 | err = db.Model(&models.User{}).Where("user_email = ?", email).Take(&user).Error 30 | if err != nil { 31 | err = errors.New("用户不存在") 32 | ch <- false 33 | return 34 | } 35 | if user.IsLock { 36 | err = errors.New("账号已锁定") 37 | ch <- false 38 | return 39 | } 40 | err = security.VerifyPassword(user.UserPassword, password) 41 | if err != nil { 42 | ch <- false 43 | return 44 | } 45 | ch <- true 46 | }(done) 47 | 48 | if channels.OK(done) { 49 | user.UserPassword = "" 50 | err, token := GenerateJWT(user) 51 | return user, err, token 52 | } 53 | return models.User{}, "", err 54 | } 55 | 56 | // SignIn method 57 | func LoginAdmin(email, password string) (string, error) { 58 | user := models.User{} 59 | var err error 60 | var db *gorm.DB 61 | done := make(chan bool) 62 | go func(ch chan<- bool) { 63 | defer close(ch) 64 | db = database.NewDb() 65 | if err != nil { 66 | ch <- false 67 | return 68 | } 69 | err = db.Debug().Model(&models.User{}).Where("user_email = ?", email).Take(&user).Error 70 | if err != nil { 71 | err = errors.New("用户不存在") 72 | ch <- false 73 | return 74 | } 75 | if user.IsLock { 76 | err = errors.New("账号已锁定,请联系管理员解封") 77 | ch <- false 78 | return 79 | } 80 | if !user.IsAdmin { 81 | err = errors.New("非管理员,禁止登录") 82 | ch <- false 83 | return 84 | } 85 | err = security.VerifyPassword(user.UserPassword, password) 86 | if err != nil { 87 | ch <- false 88 | return 89 | } 90 | ch <- true 91 | }(done) 92 | 93 | if channels.OK(done) { 94 | user.UserPassword = "" 95 | return GenerateJWT(user) 96 | } 97 | return "", err 98 | } 99 | -------------------------------------------------------------------------------- /api/controllers/controllerAliOpen.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "github.com/gin-gonic/gin" 5 | "github.com/msterzhang/onelist/plugins/alist" 6 | ) 7 | 8 | func AliOpenVideo(c *gin.Context) { 9 | aliOpenForm := alist.AliOpenForm{} 10 | err := c.ShouldBind(&aliOpenForm) 11 | if err != nil { 12 | c.JSON(200, gin.H{"code": 201, "msg": "表单解析出错!", "data": aliOpenForm}) 13 | return 14 | } 15 | data, err := alist.AlistAliOpenVideo(aliOpenForm.File, aliOpenForm.GalleryUid) 16 | if err != nil { 17 | c.JSON(200, gin.H{"code": 201, "msg": err.Error(), "data": ""}) 18 | } 19 | c.JSON(200, gin.H{"code": 200, "msg": "success", "data": data.Data}) 20 | } 21 | -------------------------------------------------------------------------------- /api/controllers/controllerApp.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "encoding/json" 5 | "strconv" 6 | "time" 7 | 8 | "github.com/gin-gonic/gin" 9 | "github.com/msterzhang/onelist/api/database" 10 | "github.com/msterzhang/onelist/api/models" 11 | "github.com/msterzhang/onelist/api/service" 12 | "github.com/msterzhang/onelist/api/utils/cache" 13 | "github.com/msterzhang/onelist/config" 14 | ) 15 | 16 | func AppIndex(c *gin.Context) { 17 | page, errPage := strconv.Atoi(c.Query("page")) 18 | size, errSize := strconv.Atoi(c.Query("size")) 19 | if errPage != nil { 20 | page = 1 21 | } 22 | if errSize != nil { 23 | size = 8 24 | } 25 | thedatas := []models.TheDataIndex{} 26 | cDb := cache.NewCache() 27 | VideoData, found := cDb.Get(string(config.SECRETKEY)) 28 | if found { 29 | err := json.Unmarshal(VideoData.([]byte), &thedatas) 30 | if err != nil { 31 | c.JSON(200, gin.H{"code": 201, "msg": err.Error(), "data": ""}) 32 | return 33 | } 34 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": thedatas}) 35 | return 36 | } 37 | db := database.NewDb() 38 | gallerys := []models.Gallery{} 39 | result := db.Model(&models.Gallery{}).Find(&gallerys) 40 | if config.DBDRIVER == "sqlite" { 41 | err := result.Limit(size).Offset((page - 1) * size).Order("datetime(updated_at) desc").Scan(&gallerys).Error 42 | if err != nil { 43 | c.JSON(200, gin.H{"code": 201, "msg": err.Error(), "data": ""}) 44 | return 45 | } 46 | } else { 47 | err := result.Limit(size).Offset((page - 1) * size).Order("-updated_at").Scan(&gallerys).Error 48 | if err != nil { 49 | c.JSON(200, gin.H{"code": 201, "msg": err.Error(), "data": ""}) 50 | return 51 | } 52 | } 53 | for _, gallery := range gallerys { 54 | if gallery.GalleryType == "tv" { 55 | thetvs := []models.TheTv{} 56 | result := db.Model(&models.TheTv{}).Find(&thetvs) 57 | if config.DBDRIVER == "sqlite" { 58 | err := result.Where("gallery_uid = ?", gallery.GalleryUid).Limit(size).Offset((page - 1) * size).Order("datetime(updated_at) desc").Scan(&thetvs).Error 59 | if err != nil { 60 | continue 61 | } 62 | } else { 63 | err := result.Where("gallery_uid = ?", gallery.GalleryUid).Limit(size).Offset((page - 1) * size).Order("-updated_at").Scan(&thetvs).Error 64 | if err != nil { 65 | continue 66 | } 67 | } 68 | thetvsNew := service.TheTvsService(thetvs, c.GetString("UserId")) 69 | thedata := models.TheDataIndex{Title: gallery.Title, GalleryUid: gallery.GalleryUid, GalleryType: gallery.GalleryType, TheTvList: thetvsNew} 70 | thedatas = append(thedatas, thedata) 71 | } else { 72 | themovies := []models.TheMovie{} 73 | result := db.Model(&models.TheMovie{}).Find(&themovies) 74 | if config.DBDRIVER == "sqlite" { 75 | err := result.Where("gallery_uid = ?", gallery.GalleryUid).Limit(size).Offset((page - 1) * size).Order("datetime(updated_at) desc").Scan(&themovies).Error 76 | if err != nil { 77 | continue 78 | } 79 | } else { 80 | err := result.Where("gallery_uid = ?", gallery.GalleryUid).Limit(size).Offset((page - 1) * size).Order("-updated_at").Scan(&themovies).Error 81 | if err != nil { 82 | continue 83 | } 84 | } 85 | themoviesNew := service.TheMoviesService(themovies, c.GetString("UserId")) 86 | thedata := models.TheDataIndex{Title: gallery.Title, GalleryUid: gallery.GalleryUid, GalleryType: gallery.GalleryType, TheMovieList: themoviesNew} 87 | thedatas = append(thedatas, thedata) 88 | } 89 | } 90 | videoText, _ := json.Marshal(thedatas) 91 | cDb.Set(string(config.SECRETKEY), videoText, 10*time.Microsecond) 92 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": thedatas}) 93 | } 94 | -------------------------------------------------------------------------------- /api/controllers/controllerBelongsToCollections.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/msterzhang/onelist/api/database" 7 | "github.com/msterzhang/onelist/api/models" 8 | "github.com/msterzhang/onelist/api/repository" 9 | "github.com/msterzhang/onelist/api/repository/crud" 10 | 11 | "github.com/gin-gonic/gin" 12 | ) 13 | 14 | func CreateBelongsToCollection(c *gin.Context) { 15 | belongstocollection := models.BelongsToCollection{} 16 | err := c.ShouldBind(&belongstocollection) 17 | if err != nil { 18 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": belongstocollection}) 19 | return 20 | } 21 | db := database.NewDb() 22 | repo := crud.NewRepositoryBelongsToCollectionsCRUD(db) 23 | func(belongstocollectionRepository repository.BelongsToCollectionRepository) { 24 | belongstocollection, err := belongstocollectionRepository.Save(belongstocollection) 25 | if err != nil { 26 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败!", "data": belongstocollection}) 27 | return 28 | } 29 | c.JSON(200, gin.H{"code": 200, "msg": "创建成功!", "data": belongstocollection}) 30 | }(repo) 31 | } 32 | 33 | func DeleteBelongsToCollectionById(c *gin.Context) { 34 | id := c.Query("id") 35 | db := database.NewDb() 36 | repo := crud.NewRepositoryBelongsToCollectionsCRUD(db) 37 | func(belongstocollectionRepository repository.BelongsToCollectionRepository) { 38 | belongstocollection, err := belongstocollectionRepository.DeleteByID(id) 39 | if err != nil { 40 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": belongstocollection}) 41 | return 42 | } 43 | c.JSON(200, gin.H{"code": 200, "msg": "删除资源成功!", "data": belongstocollection}) 44 | }(repo) 45 | } 46 | 47 | func UpdateBelongsToCollectionById(c *gin.Context) { 48 | id := c.Query("id") 49 | belongstocollection := models.BelongsToCollection{} 50 | err := c.ShouldBind(&belongstocollection) 51 | if err != nil { 52 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": belongstocollection}) 53 | return 54 | } 55 | db := database.NewDb() 56 | repo := crud.NewRepositoryBelongsToCollectionsCRUD(db) 57 | func(belongstocollectionRepository repository.BelongsToCollectionRepository) { 58 | belongstocollection, err := belongstocollectionRepository.UpdateByID(id, belongstocollection) 59 | if err != nil { 60 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": belongstocollection}) 61 | return 62 | } 63 | c.JSON(200, gin.H{"code": 200, "msg": "更新资源成功!", "data": belongstocollection}) 64 | }(repo) 65 | } 66 | 67 | func GetBelongsToCollectionById(c *gin.Context) { 68 | id := c.Query("id") 69 | db := database.NewDb() 70 | repo := crud.NewRepositoryBelongsToCollectionsCRUD(db) 71 | func(belongstocollectionRepository repository.BelongsToCollectionRepository) { 72 | belongstocollection, err := belongstocollectionRepository.FindByID(id) 73 | if err != nil { 74 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": belongstocollection}) 75 | return 76 | } 77 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": belongstocollection}) 78 | }(repo) 79 | } 80 | 81 | func GetBelongsToCollectionList(c *gin.Context) { 82 | page, errPage := strconv.Atoi(c.Query("page")) 83 | size, errSize := strconv.Atoi(c.Query("size")) 84 | if errPage != nil { 85 | page = 1 86 | } 87 | if errSize != nil { 88 | size = 8 89 | } 90 | db := database.NewDb() 91 | repo := crud.NewRepositoryBelongsToCollectionsCRUD(db) 92 | func(belongstocollectionRepository repository.BelongsToCollectionRepository) { 93 | belongstocollections, num, err := belongstocollectionRepository.FindAll(page, size) 94 | if err != nil { 95 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": belongstocollections, "num": num}) 96 | return 97 | } 98 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": belongstocollections, "num": num}) 99 | }(repo) 100 | } 101 | 102 | func SearchBelongsToCollection(c *gin.Context) { 103 | q := c.Query("q") 104 | if len(q) == 0 { 105 | c.JSON(200, gin.H{"code": 201, "msg": "参数错误!", "data": ""}) 106 | return 107 | } 108 | page, errPage := strconv.Atoi(c.Query("page")) 109 | size, errSize := strconv.Atoi(c.Query("size")) 110 | if errPage != nil { 111 | page = 1 112 | } 113 | if errSize != nil { 114 | size = 8 115 | } 116 | db := database.NewDb() 117 | repo := crud.NewRepositoryBelongsToCollectionsCRUD(db) 118 | func(belongstocollectionRepository repository.BelongsToCollectionRepository) { 119 | belongstocollections, num, err := belongstocollectionRepository.Search(q, page, size) 120 | if err != nil { 121 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": belongstocollections, "num": num}) 122 | return 123 | } 124 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": belongstocollections, "num": num}) 125 | }(repo) 126 | } 127 | -------------------------------------------------------------------------------- /api/controllers/controllerCastItems.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/msterzhang/onelist/api/database" 7 | "github.com/msterzhang/onelist/api/models" 8 | "github.com/msterzhang/onelist/api/repository" 9 | "github.com/msterzhang/onelist/api/repository/crud" 10 | 11 | "github.com/gin-gonic/gin" 12 | ) 13 | 14 | func CreateCastItem(c *gin.Context) { 15 | castitem := models.CastItem{} 16 | err := c.ShouldBind(&castitem) 17 | if err != nil { 18 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": castitem}) 19 | return 20 | } 21 | db := database.NewDb() 22 | repo := crud.NewRepositoryCastItemsCRUD(db) 23 | func(castitemRepository repository.CastItemRepository) { 24 | castitem, err := castitemRepository.Save(castitem) 25 | if err != nil { 26 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败!", "data": castitem}) 27 | return 28 | } 29 | c.JSON(200, gin.H{"code": 200, "msg": "创建成功!", "data": castitem}) 30 | }(repo) 31 | } 32 | 33 | func DeleteCastItemById(c *gin.Context) { 34 | id := c.Query("id") 35 | db := database.NewDb() 36 | repo := crud.NewRepositoryCastItemsCRUD(db) 37 | func(castitemRepository repository.CastItemRepository) { 38 | castitem, err := castitemRepository.DeleteByID(id) 39 | if err != nil { 40 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": castitem}) 41 | return 42 | } 43 | c.JSON(200, gin.H{"code": 200, "msg": "删除资源成功!", "data": castitem}) 44 | }(repo) 45 | } 46 | 47 | func UpdateCastItemById(c *gin.Context) { 48 | id := c.Query("id") 49 | castitem := models.CastItem{} 50 | err := c.ShouldBind(&castitem) 51 | if err != nil { 52 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": castitem}) 53 | return 54 | } 55 | db := database.NewDb() 56 | repo := crud.NewRepositoryCastItemsCRUD(db) 57 | func(castitemRepository repository.CastItemRepository) { 58 | castitem, err := castitemRepository.UpdateByID(id, castitem) 59 | if err != nil { 60 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": castitem}) 61 | return 62 | } 63 | c.JSON(200, gin.H{"code": 200, "msg": "更新资源成功!", "data": castitem}) 64 | }(repo) 65 | } 66 | 67 | func GetCastItemById(c *gin.Context) { 68 | id := c.Query("id") 69 | db := database.NewDb() 70 | repo := crud.NewRepositoryCastItemsCRUD(db) 71 | func(castitemRepository repository.CastItemRepository) { 72 | castitem, err := castitemRepository.FindByID(id) 73 | if err != nil { 74 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": castitem}) 75 | return 76 | } 77 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": castitem}) 78 | }(repo) 79 | } 80 | 81 | func GetCastItemList(c *gin.Context) { 82 | page, errPage := strconv.Atoi(c.Query("page")) 83 | size, errSize := strconv.Atoi(c.Query("size")) 84 | if errPage != nil { 85 | page = 1 86 | } 87 | if errSize != nil { 88 | size = 8 89 | } 90 | db := database.NewDb() 91 | repo := crud.NewRepositoryCastItemsCRUD(db) 92 | func(castitemRepository repository.CastItemRepository) { 93 | castitems, num, err := castitemRepository.FindAll(page, size) 94 | if err != nil { 95 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": castitems, "num": num}) 96 | return 97 | } 98 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": castitems, "num": num}) 99 | }(repo) 100 | } 101 | 102 | func SearchCastItem(c *gin.Context) { 103 | q := c.Query("q") 104 | if len(q) == 0 { 105 | c.JSON(200, gin.H{"code": 201, "msg": "参数错误!", "data": ""}) 106 | return 107 | } 108 | page, errPage := strconv.Atoi(c.Query("page")) 109 | size, errSize := strconv.Atoi(c.Query("size")) 110 | if errPage != nil { 111 | page = 1 112 | } 113 | if errSize != nil { 114 | size = 8 115 | } 116 | db := database.NewDb() 117 | repo := crud.NewRepositoryCastItemsCRUD(db) 118 | func(castitemRepository repository.CastItemRepository) { 119 | castitems, num, err := castitemRepository.Search(q, page, size) 120 | if err != nil { 121 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": castitems, "num": num}) 122 | return 123 | } 124 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": castitems, "num": num}) 125 | }(repo) 126 | } 127 | -------------------------------------------------------------------------------- /api/controllers/controllerConfig.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "github.com/gin-gonic/gin" 5 | "github.com/msterzhang/onelist/api/models" 6 | "github.com/msterzhang/onelist/config" 7 | ) 8 | 9 | func GetWebConfig(c *gin.Context) { 10 | configData := config.GetConfig() 11 | configData.KeyDb="" 12 | c.JSON(200, gin.H{"code": 200, "msg": "获取成功!", "data": configData}) 13 | } 14 | 15 | 16 | func GetConfig(c *gin.Context) { 17 | configData := config.GetConfig() 18 | c.JSON(200, gin.H{"code": 200, "msg": "获取成功!", "data": configData}) 19 | } 20 | 21 | func SaveConfig(c *gin.Context) { 22 | configData := models.Config{} 23 | err := c.ShouldBind(&configData) 24 | if err != nil { 25 | c.JSON(200, gin.H{"code": 201, "msg": err.Error(), "data": ""}) 26 | return 27 | } 28 | data, err := config.SaveConfig(configData) 29 | if err != nil { 30 | c.JSON(200, gin.H{"code": 201, "msg": err.Error(), "data": ""}) 31 | return 32 | } 33 | c.JSON(200, gin.H{"code": 200, "msg": "保存成功!", "data": data}) 34 | } 35 | -------------------------------------------------------------------------------- /api/controllers/controllerCrewItems.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/msterzhang/onelist/api/database" 7 | "github.com/msterzhang/onelist/api/models" 8 | "github.com/msterzhang/onelist/api/repository" 9 | "github.com/msterzhang/onelist/api/repository/crud" 10 | 11 | "github.com/gin-gonic/gin" 12 | ) 13 | 14 | func CreateCrewItem(c *gin.Context) { 15 | crewitem := models.CrewItem{} 16 | err := c.ShouldBind(&crewitem) 17 | if err != nil { 18 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": crewitem}) 19 | return 20 | } 21 | db := database.NewDb() 22 | repo := crud.NewRepositoryCrewItemsCRUD(db) 23 | func(crewitemRepository repository.CrewItemRepository) { 24 | crewitem, err := crewitemRepository.Save(crewitem) 25 | if err != nil { 26 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败!", "data": crewitem}) 27 | return 28 | } 29 | c.JSON(200, gin.H{"code": 200, "msg": "创建成功!", "data": crewitem}) 30 | }(repo) 31 | } 32 | 33 | func DeleteCrewItemById(c *gin.Context) { 34 | id := c.Query("id") 35 | db := database.NewDb() 36 | repo := crud.NewRepositoryCrewItemsCRUD(db) 37 | func(crewitemRepository repository.CrewItemRepository) { 38 | crewitem, err := crewitemRepository.DeleteByID(id) 39 | if err != nil { 40 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": crewitem}) 41 | return 42 | } 43 | c.JSON(200, gin.H{"code": 200, "msg": "删除资源成功!", "data": crewitem}) 44 | }(repo) 45 | } 46 | 47 | func UpdateCrewItemById(c *gin.Context) { 48 | id := c.Query("id") 49 | crewitem := models.CrewItem{} 50 | err := c.ShouldBind(&crewitem) 51 | if err != nil { 52 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": crewitem}) 53 | return 54 | } 55 | db := database.NewDb() 56 | repo := crud.NewRepositoryCrewItemsCRUD(db) 57 | func(crewitemRepository repository.CrewItemRepository) { 58 | crewitem, err := crewitemRepository.UpdateByID(id, crewitem) 59 | if err != nil { 60 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": crewitem}) 61 | return 62 | } 63 | c.JSON(200, gin.H{"code": 200, "msg": "更新资源成功!", "data": crewitem}) 64 | }(repo) 65 | } 66 | 67 | func GetCrewItemById(c *gin.Context) { 68 | id := c.Query("id") 69 | db := database.NewDb() 70 | repo := crud.NewRepositoryCrewItemsCRUD(db) 71 | func(crewitemRepository repository.CrewItemRepository) { 72 | crewitem, err := crewitemRepository.FindByID(id) 73 | if err != nil { 74 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": crewitem}) 75 | return 76 | } 77 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": crewitem}) 78 | }(repo) 79 | } 80 | 81 | func GetCrewItemList(c *gin.Context) { 82 | page, errPage := strconv.Atoi(c.Query("page")) 83 | size, errSize := strconv.Atoi(c.Query("size")) 84 | if errPage != nil { 85 | page = 1 86 | } 87 | if errSize != nil { 88 | size = 8 89 | } 90 | db := database.NewDb() 91 | repo := crud.NewRepositoryCrewItemsCRUD(db) 92 | func(crewitemRepository repository.CrewItemRepository) { 93 | crewitems, num, err := crewitemRepository.FindAll(page, size) 94 | if err != nil { 95 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": crewitems, "num": num}) 96 | return 97 | } 98 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": crewitems, "num": num}) 99 | }(repo) 100 | } 101 | 102 | func SearchCrewItem(c *gin.Context) { 103 | q := c.Query("q") 104 | if len(q) == 0 { 105 | c.JSON(200, gin.H{"code": 201, "msg": "参数错误!", "data": ""}) 106 | return 107 | } 108 | page, errPage := strconv.Atoi(c.Query("page")) 109 | size, errSize := strconv.Atoi(c.Query("size")) 110 | if errPage != nil { 111 | page = 1 112 | } 113 | if errSize != nil { 114 | size = 8 115 | } 116 | db := database.NewDb() 117 | repo := crud.NewRepositoryCrewItemsCRUD(db) 118 | func(crewitemRepository repository.CrewItemRepository) { 119 | crewitems, num, err := crewitemRepository.Search(q, page, size) 120 | if err != nil { 121 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": crewitems, "num": num}) 122 | return 123 | } 124 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": crewitems, "num": num}) 125 | }(repo) 126 | } 127 | -------------------------------------------------------------------------------- /api/controllers/controllerEpisodes.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/msterzhang/onelist/api/database" 7 | "github.com/msterzhang/onelist/api/models" 8 | "github.com/msterzhang/onelist/api/repository" 9 | "github.com/msterzhang/onelist/api/repository/crud" 10 | 11 | "github.com/gin-gonic/gin" 12 | ) 13 | 14 | func CreateEpisode(c *gin.Context) { 15 | episode := models.Episode{} 16 | err := c.ShouldBind(&episode) 17 | if err != nil { 18 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": episode}) 19 | return 20 | } 21 | db := database.NewDb() 22 | repo := crud.NewRepositoryEpisodesCRUD(db) 23 | func(episodeRepository repository.EpisodeRepository) { 24 | episode, err := episodeRepository.Save(episode) 25 | if err != nil { 26 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败!", "data": episode}) 27 | return 28 | } 29 | c.JSON(200, gin.H{"code": 200, "msg": "创建成功!", "data": episode}) 30 | }(repo) 31 | } 32 | 33 | func DeleteEpisodeById(c *gin.Context) { 34 | id := c.Query("id") 35 | db := database.NewDb() 36 | repo := crud.NewRepositoryEpisodesCRUD(db) 37 | func(episodeRepository repository.EpisodeRepository) { 38 | episode, err := episodeRepository.DeleteByID(id) 39 | if err != nil { 40 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": episode}) 41 | return 42 | } 43 | c.JSON(200, gin.H{"code": 200, "msg": "删除资源成功!", "data": episode}) 44 | }(repo) 45 | } 46 | 47 | func UpdateEpisodeById(c *gin.Context) { 48 | id := c.Query("id") 49 | episode := models.Episode{} 50 | err := c.ShouldBind(&episode) 51 | if err != nil { 52 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": episode}) 53 | return 54 | } 55 | db := database.NewDb() 56 | repo := crud.NewRepositoryEpisodesCRUD(db) 57 | func(episodeRepository repository.EpisodeRepository) { 58 | episode, err := episodeRepository.UpdateByID(id, episode) 59 | if err != nil { 60 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": episode}) 61 | return 62 | } 63 | c.JSON(200, gin.H{"code": 200, "msg": "更新资源成功!", "data": episode}) 64 | }(repo) 65 | } 66 | 67 | func GetEpisodeById(c *gin.Context) { 68 | id := c.Query("id") 69 | db := database.NewDb() 70 | repo := crud.NewRepositoryEpisodesCRUD(db) 71 | func(episodeRepository repository.EpisodeRepository) { 72 | episode, err := episodeRepository.FindByID(id) 73 | if err != nil { 74 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": episode}) 75 | return 76 | } 77 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": episode}) 78 | }(repo) 79 | } 80 | 81 | func GetEpisodeList(c *gin.Context) { 82 | page, errPage := strconv.Atoi(c.Query("page")) 83 | size, errSize := strconv.Atoi(c.Query("size")) 84 | if errPage != nil { 85 | page = 1 86 | } 87 | if errSize != nil { 88 | size = 8 89 | } 90 | db := database.NewDb() 91 | repo := crud.NewRepositoryEpisodesCRUD(db) 92 | func(episodeRepository repository.EpisodeRepository) { 93 | episodes, num, err := episodeRepository.FindAll(page, size) 94 | if err != nil { 95 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": episodes, "num": num}) 96 | return 97 | } 98 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": episodes, "num": num}) 99 | }(repo) 100 | } 101 | 102 | func SearchEpisode(c *gin.Context) { 103 | q := c.Query("q") 104 | if len(q) == 0 { 105 | c.JSON(200, gin.H{"code": 201, "msg": "参数错误!", "data": ""}) 106 | return 107 | } 108 | page, errPage := strconv.Atoi(c.Query("page")) 109 | size, errSize := strconv.Atoi(c.Query("size")) 110 | if errPage != nil { 111 | page = 1 112 | } 113 | if errSize != nil { 114 | size = 8 115 | } 116 | db := database.NewDb() 117 | repo := crud.NewRepositoryEpisodesCRUD(db) 118 | func(episodeRepository repository.EpisodeRepository) { 119 | episodes, num, err := episodeRepository.Search(q, page, size) 120 | if err != nil { 121 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": episodes, "num": num}) 122 | return 123 | } 124 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": episodes, "num": num}) 125 | }(repo) 126 | } 127 | -------------------------------------------------------------------------------- /api/controllers/controllerFile.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "os" 7 | "path" 8 | "path/filepath" 9 | 10 | "github.com/gin-gonic/gin" 11 | "github.com/msterzhang/onelist/api/utils/dir" 12 | "github.com/msterzhang/onelist/api/utils/tools" 13 | ) 14 | 15 | // 图片文件服务 16 | func ImgServer(c *gin.Context) { 17 | path := c.Param("path") 18 | filePath := "images" + path 19 | c.Writer.WriteHeader(200) 20 | b, err := os.ReadFile(filePath) 21 | if err != nil { 22 | c.Writer.WriteHeader(http.StatusNotFound) 23 | c.Writer.Flush() 24 | return 25 | } 26 | _, err = c.Writer.Write(b) 27 | if err != nil { 28 | c.Writer.WriteHeader(http.StatusNoContent) 29 | c.Writer.Flush() 30 | return 31 | } 32 | c.Writer.Header().Add("Content-Type", "image/*") 33 | c.Writer.Flush() 34 | } 35 | 36 | // 本地文件服务 37 | func FileServer(c *gin.Context) { 38 | file := c.Param("path") 39 | if len(file) < 1 { 40 | c.String(http.StatusBadRequest, "文件不存在!") 41 | return 42 | } 43 | file = file[1:] 44 | if !dir.FileExists(file) { 45 | c.String(http.StatusBadRequest, "文件不存在!") 46 | return 47 | } 48 | fileName := filepath.Base(file) 49 | c.Header("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, fileName)) 50 | c.Header("Content-Type", "application/octet-stream") 51 | c.File(file) 52 | } 53 | 54 | func GalleryImgServer(c *gin.Context) { 55 | path := c.Param("path") 56 | filePath := "./images" + path 57 | c.Writer.WriteHeader(200) 58 | b, err := os.ReadFile(filePath) 59 | if err != nil { 60 | c.Writer.WriteHeader(http.StatusNotFound) 61 | c.Writer.Flush() 62 | return 63 | } 64 | _, err = c.Writer.Write(b) 65 | if err != nil { 66 | c.Writer.WriteHeader(http.StatusNoContent) 67 | c.Writer.Flush() 68 | return 69 | } 70 | c.Writer.Header().Add("Content-Type", "image/*") 71 | c.Writer.Flush() 72 | } 73 | 74 | func FileUpload(c *gin.Context) { 75 | file, err := c.FormFile("file") 76 | if err != nil { 77 | c.String(http.StatusBadRequest, "没有获得文件!") 78 | return 79 | } 80 | id := tools.RandStringRunes(16) 81 | dst := "./images/w355_and_h200_multi_faces/" + id + path.Ext(file.Filename) 82 | data := "/gallery/w355_and_h200_multi_faces/" + id + path.Ext(file.Filename) 83 | c.SaveUploadedFile(file, dst) 84 | c.JSON(200, gin.H{"code": 200, "msg": "上传成功!", "data": data}) 85 | } 86 | -------------------------------------------------------------------------------- /api/controllers/controllerLastEpisodeToAirs.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/msterzhang/onelist/api/database" 7 | "github.com/msterzhang/onelist/api/models" 8 | "github.com/msterzhang/onelist/api/repository" 9 | "github.com/msterzhang/onelist/api/repository/crud" 10 | 11 | "github.com/gin-gonic/gin" 12 | ) 13 | 14 | func CreateLastEpisodeToAir(c *gin.Context) { 15 | lastepisodetoair := models.LastEpisodeToAir{} 16 | err := c.ShouldBind(&lastepisodetoair) 17 | if err != nil { 18 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": lastepisodetoair}) 19 | return 20 | } 21 | db := database.NewDb() 22 | repo := crud.NewRepositoryLastEpisodeToAirsCRUD(db) 23 | func(lastepisodetoairRepository repository.LastEpisodeToAirRepository) { 24 | lastepisodetoair, err := lastepisodetoairRepository.Save(lastepisodetoair) 25 | if err != nil { 26 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败!", "data": lastepisodetoair}) 27 | return 28 | } 29 | c.JSON(200, gin.H{"code": 200, "msg": "创建成功!", "data": lastepisodetoair}) 30 | }(repo) 31 | } 32 | 33 | func DeleteLastEpisodeToAirById(c *gin.Context) { 34 | id := c.Query("id") 35 | db := database.NewDb() 36 | repo := crud.NewRepositoryLastEpisodeToAirsCRUD(db) 37 | func(lastepisodetoairRepository repository.LastEpisodeToAirRepository) { 38 | lastepisodetoair, err := lastepisodetoairRepository.DeleteByID(id) 39 | if err != nil { 40 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": lastepisodetoair}) 41 | return 42 | } 43 | c.JSON(200, gin.H{"code": 200, "msg": "删除资源成功!", "data": lastepisodetoair}) 44 | }(repo) 45 | } 46 | 47 | func UpdateLastEpisodeToAirById(c *gin.Context) { 48 | id := c.Query("id") 49 | lastepisodetoair := models.LastEpisodeToAir{} 50 | err := c.ShouldBind(&lastepisodetoair) 51 | if err != nil { 52 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": lastepisodetoair}) 53 | return 54 | } 55 | db := database.NewDb() 56 | repo := crud.NewRepositoryLastEpisodeToAirsCRUD(db) 57 | func(lastepisodetoairRepository repository.LastEpisodeToAirRepository) { 58 | lastepisodetoair, err := lastepisodetoairRepository.UpdateByID(id, lastepisodetoair) 59 | if err != nil { 60 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": lastepisodetoair}) 61 | return 62 | } 63 | c.JSON(200, gin.H{"code": 200, "msg": "更新资源成功!", "data": lastepisodetoair}) 64 | }(repo) 65 | } 66 | 67 | func GetLastEpisodeToAirById(c *gin.Context) { 68 | id := c.Query("id") 69 | db := database.NewDb() 70 | repo := crud.NewRepositoryLastEpisodeToAirsCRUD(db) 71 | func(lastepisodetoairRepository repository.LastEpisodeToAirRepository) { 72 | lastepisodetoair, err := lastepisodetoairRepository.FindByID(id) 73 | if err != nil { 74 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": lastepisodetoair}) 75 | return 76 | } 77 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": lastepisodetoair}) 78 | }(repo) 79 | } 80 | 81 | func GetLastEpisodeToAirList(c *gin.Context) { 82 | page, errPage := strconv.Atoi(c.Query("page")) 83 | size, errSize := strconv.Atoi(c.Query("size")) 84 | if errPage != nil { 85 | page = 1 86 | } 87 | if errSize != nil { 88 | size = 8 89 | } 90 | db := database.NewDb() 91 | repo := crud.NewRepositoryLastEpisodeToAirsCRUD(db) 92 | func(lastepisodetoairRepository repository.LastEpisodeToAirRepository) { 93 | lastepisodetoairs, num, err := lastepisodetoairRepository.FindAll(page, size) 94 | if err != nil { 95 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": lastepisodetoairs, "num": num}) 96 | return 97 | } 98 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": lastepisodetoairs, "num": num}) 99 | }(repo) 100 | } 101 | 102 | func SearchLastEpisodeToAir(c *gin.Context) { 103 | q := c.Query("q") 104 | if len(q) == 0 { 105 | c.JSON(200, gin.H{"code": 201, "msg": "参数错误!", "data": ""}) 106 | return 107 | } 108 | page, errPage := strconv.Atoi(c.Query("page")) 109 | size, errSize := strconv.Atoi(c.Query("size")) 110 | if errPage != nil { 111 | page = 1 112 | } 113 | if errSize != nil { 114 | size = 8 115 | } 116 | db := database.NewDb() 117 | repo := crud.NewRepositoryLastEpisodeToAirsCRUD(db) 118 | func(lastepisodetoairRepository repository.LastEpisodeToAirRepository) { 119 | lastepisodetoairs, num, err := lastepisodetoairRepository.Search(q, page, size) 120 | if err != nil { 121 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": lastepisodetoairs, "num": num}) 122 | return 123 | } 124 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": lastepisodetoairs, "num": num}) 125 | }(repo) 126 | } 127 | -------------------------------------------------------------------------------- /api/controllers/controllerNetworkss.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/msterzhang/onelist/api/database" 7 | "github.com/msterzhang/onelist/api/models" 8 | "github.com/msterzhang/onelist/api/repository" 9 | "github.com/msterzhang/onelist/api/repository/crud" 10 | 11 | "github.com/gin-gonic/gin" 12 | ) 13 | 14 | func CreateNetworks(c *gin.Context) { 15 | networks := models.Networks{} 16 | err := c.ShouldBind(&networks) 17 | if err != nil { 18 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": networks}) 19 | return 20 | } 21 | db := database.NewDb() 22 | repo := crud.NewRepositoryNetworkssCRUD(db) 23 | func(networksRepository repository.NetworksRepository) { 24 | networks, err := networksRepository.Save(networks) 25 | if err != nil { 26 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败!", "data": networks}) 27 | return 28 | } 29 | c.JSON(200, gin.H{"code": 200, "msg": "创建成功!", "data": networks}) 30 | }(repo) 31 | } 32 | 33 | func DeleteNetworksById(c *gin.Context) { 34 | id := c.Query("id") 35 | db := database.NewDb() 36 | repo := crud.NewRepositoryNetworkssCRUD(db) 37 | func(networksRepository repository.NetworksRepository) { 38 | networks, err := networksRepository.DeleteByID(id) 39 | if err != nil { 40 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": networks}) 41 | return 42 | } 43 | c.JSON(200, gin.H{"code": 200, "msg": "删除资源成功!", "data": networks}) 44 | }(repo) 45 | } 46 | 47 | func UpdateNetworksById(c *gin.Context) { 48 | id := c.Query("id") 49 | networks := models.Networks{} 50 | err := c.ShouldBind(&networks) 51 | if err != nil { 52 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": networks}) 53 | return 54 | } 55 | db := database.NewDb() 56 | repo := crud.NewRepositoryNetworkssCRUD(db) 57 | func(networksRepository repository.NetworksRepository) { 58 | networks, err := networksRepository.UpdateByID(id, networks) 59 | if err != nil { 60 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": networks}) 61 | return 62 | } 63 | c.JSON(200, gin.H{"code": 200, "msg": "更新资源成功!", "data": networks}) 64 | }(repo) 65 | } 66 | 67 | func GetNetworksById(c *gin.Context) { 68 | id := c.Query("id") 69 | db := database.NewDb() 70 | repo := crud.NewRepositoryNetworkssCRUD(db) 71 | func(networksRepository repository.NetworksRepository) { 72 | networks, err := networksRepository.FindByID(id) 73 | if err != nil { 74 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": networks}) 75 | return 76 | } 77 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": networks}) 78 | }(repo) 79 | } 80 | 81 | func GetNetworksList(c *gin.Context) { 82 | page, errPage := strconv.Atoi(c.Query("page")) 83 | size, errSize := strconv.Atoi(c.Query("size")) 84 | if errPage != nil { 85 | page = 1 86 | } 87 | if errSize != nil { 88 | size = 8 89 | } 90 | db := database.NewDb() 91 | repo := crud.NewRepositoryNetworkssCRUD(db) 92 | func(networksRepository repository.NetworksRepository) { 93 | networkss, num, err := networksRepository.FindAll(page, size) 94 | if err != nil { 95 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": networkss, "num": num}) 96 | return 97 | } 98 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": networkss, "num": num}) 99 | }(repo) 100 | } 101 | 102 | func SearchNetworks(c *gin.Context) { 103 | q := c.Query("q") 104 | if len(q) == 0 { 105 | c.JSON(200, gin.H{"code": 201, "msg": "参数错误!", "data": ""}) 106 | return 107 | } 108 | page, errPage := strconv.Atoi(c.Query("page")) 109 | size, errSize := strconv.Atoi(c.Query("size")) 110 | if errPage != nil { 111 | page = 1 112 | } 113 | if errSize != nil { 114 | size = 8 115 | } 116 | db := database.NewDb() 117 | repo := crud.NewRepositoryNetworkssCRUD(db) 118 | func(networksRepository repository.NetworksRepository) { 119 | networkss, num, err := networksRepository.Search(q, page, size) 120 | if err != nil { 121 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": networkss, "num": num}) 122 | return 123 | } 124 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": networkss, "num": num}) 125 | }(repo) 126 | } 127 | -------------------------------------------------------------------------------- /api/controllers/controllerNextEpisodeToAirs.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/msterzhang/onelist/api/database" 7 | "github.com/msterzhang/onelist/api/models" 8 | "github.com/msterzhang/onelist/api/repository" 9 | "github.com/msterzhang/onelist/api/repository/crud" 10 | 11 | "github.com/gin-gonic/gin" 12 | ) 13 | 14 | func CreateNextEpisodeToAir(c *gin.Context) { 15 | nextepisodetoair := models.NextEpisodeToAir{} 16 | err := c.ShouldBind(&nextepisodetoair) 17 | if err != nil { 18 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": nextepisodetoair}) 19 | return 20 | } 21 | db := database.NewDb() 22 | repo := crud.NewRepositoryNextEpisodeToAirsCRUD(db) 23 | func(nextepisodetoairRepository repository.NextEpisodeToAirRepository) { 24 | nextepisodetoair, err := nextepisodetoairRepository.Save(nextepisodetoair) 25 | if err != nil { 26 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败!", "data": nextepisodetoair}) 27 | return 28 | } 29 | c.JSON(200, gin.H{"code": 200, "msg": "创建成功!", "data": nextepisodetoair}) 30 | }(repo) 31 | } 32 | 33 | func DeleteNextEpisodeToAirById(c *gin.Context) { 34 | id := c.Query("id") 35 | db := database.NewDb() 36 | repo := crud.NewRepositoryNextEpisodeToAirsCRUD(db) 37 | func(nextepisodetoairRepository repository.NextEpisodeToAirRepository) { 38 | nextepisodetoair, err := nextepisodetoairRepository.DeleteByID(id) 39 | if err != nil { 40 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": nextepisodetoair}) 41 | return 42 | } 43 | c.JSON(200, gin.H{"code": 200, "msg": "删除资源成功!", "data": nextepisodetoair}) 44 | }(repo) 45 | } 46 | 47 | func UpdateNextEpisodeToAirById(c *gin.Context) { 48 | id := c.Query("id") 49 | nextepisodetoair := models.NextEpisodeToAir{} 50 | err := c.ShouldBind(&nextepisodetoair) 51 | if err != nil { 52 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": nextepisodetoair}) 53 | return 54 | } 55 | db := database.NewDb() 56 | repo := crud.NewRepositoryNextEpisodeToAirsCRUD(db) 57 | func(nextepisodetoairRepository repository.NextEpisodeToAirRepository) { 58 | nextepisodetoair, err := nextepisodetoairRepository.UpdateByID(id, nextepisodetoair) 59 | if err != nil { 60 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": nextepisodetoair}) 61 | return 62 | } 63 | c.JSON(200, gin.H{"code": 200, "msg": "更新资源成功!", "data": nextepisodetoair}) 64 | }(repo) 65 | } 66 | 67 | func GetNextEpisodeToAirById(c *gin.Context) { 68 | id := c.Query("id") 69 | db := database.NewDb() 70 | repo := crud.NewRepositoryNextEpisodeToAirsCRUD(db) 71 | func(nextepisodetoairRepository repository.NextEpisodeToAirRepository) { 72 | nextepisodetoair, err := nextepisodetoairRepository.FindByID(id) 73 | if err != nil { 74 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": nextepisodetoair}) 75 | return 76 | } 77 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": nextepisodetoair}) 78 | }(repo) 79 | } 80 | 81 | func GetNextEpisodeToAirList(c *gin.Context) { 82 | page, errPage := strconv.Atoi(c.Query("page")) 83 | size, errSize := strconv.Atoi(c.Query("size")) 84 | if errPage != nil { 85 | page = 1 86 | } 87 | if errSize != nil { 88 | size = 8 89 | } 90 | db := database.NewDb() 91 | repo := crud.NewRepositoryNextEpisodeToAirsCRUD(db) 92 | func(nextepisodetoairRepository repository.NextEpisodeToAirRepository) { 93 | nextepisodetoairs, num, err := nextepisodetoairRepository.FindAll(page, size) 94 | if err != nil { 95 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": nextepisodetoairs, "num": num}) 96 | return 97 | } 98 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": nextepisodetoairs, "num": num}) 99 | }(repo) 100 | } 101 | 102 | func SearchNextEpisodeToAir(c *gin.Context) { 103 | q := c.Query("q") 104 | if len(q) == 0 { 105 | c.JSON(200, gin.H{"code": 201, "msg": "参数错误!", "data": ""}) 106 | return 107 | } 108 | page, errPage := strconv.Atoi(c.Query("page")) 109 | size, errSize := strconv.Atoi(c.Query("size")) 110 | if errPage != nil { 111 | page = 1 112 | } 113 | if errSize != nil { 114 | size = 8 115 | } 116 | db := database.NewDb() 117 | repo := crud.NewRepositoryNextEpisodeToAirsCRUD(db) 118 | func(nextepisodetoairRepository repository.NextEpisodeToAirRepository) { 119 | nextepisodetoairs, num, err := nextepisodetoairRepository.Search(q, page, size) 120 | if err != nil { 121 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": nextepisodetoairs, "num": num}) 122 | return 123 | } 124 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": nextepisodetoairs, "num": num}) 125 | }(repo) 126 | } 127 | -------------------------------------------------------------------------------- /api/controllers/controllerProductionCompanies.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/msterzhang/onelist/api/database" 7 | "github.com/msterzhang/onelist/api/models" 8 | "github.com/msterzhang/onelist/api/repository" 9 | "github.com/msterzhang/onelist/api/repository/crud" 10 | 11 | "github.com/gin-gonic/gin" 12 | ) 13 | 14 | func CreateProductionCompanie(c *gin.Context) { 15 | productioncompanie := models.ProductionCompanie{} 16 | err := c.ShouldBind(&productioncompanie) 17 | if err != nil { 18 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": productioncompanie}) 19 | return 20 | } 21 | db := database.NewDb() 22 | repo := crud.NewRepositoryProductionCompaniesCRUD(db) 23 | func(productioncompanieRepository repository.ProductionCompanieRepository) { 24 | productioncompanie, err := productioncompanieRepository.Save(productioncompanie) 25 | if err != nil { 26 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败!", "data": productioncompanie}) 27 | return 28 | } 29 | c.JSON(200, gin.H{"code": 200, "msg": "创建成功!", "data": productioncompanie}) 30 | }(repo) 31 | } 32 | 33 | func DeleteProductionCompanieById(c *gin.Context) { 34 | id := c.Query("id") 35 | db := database.NewDb() 36 | repo := crud.NewRepositoryProductionCompaniesCRUD(db) 37 | func(productioncompanieRepository repository.ProductionCompanieRepository) { 38 | productioncompanie, err := productioncompanieRepository.DeleteByID(id) 39 | if err != nil { 40 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": productioncompanie}) 41 | return 42 | } 43 | c.JSON(200, gin.H{"code": 200, "msg": "删除资源成功!", "data": productioncompanie}) 44 | }(repo) 45 | } 46 | 47 | func UpdateProductionCompanieById(c *gin.Context) { 48 | id := c.Query("id") 49 | productioncompanie := models.ProductionCompanie{} 50 | err := c.ShouldBind(&productioncompanie) 51 | if err != nil { 52 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": productioncompanie}) 53 | return 54 | } 55 | db := database.NewDb() 56 | repo := crud.NewRepositoryProductionCompaniesCRUD(db) 57 | func(productioncompanieRepository repository.ProductionCompanieRepository) { 58 | productioncompanie, err := productioncompanieRepository.UpdateByID(id, productioncompanie) 59 | if err != nil { 60 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": productioncompanie}) 61 | return 62 | } 63 | c.JSON(200, gin.H{"code": 200, "msg": "更新资源成功!", "data": productioncompanie}) 64 | }(repo) 65 | } 66 | 67 | func GetProductionCompanieById(c *gin.Context) { 68 | id := c.Query("id") 69 | db := database.NewDb() 70 | repo := crud.NewRepositoryProductionCompaniesCRUD(db) 71 | func(productioncompanieRepository repository.ProductionCompanieRepository) { 72 | productioncompanie, err := productioncompanieRepository.FindByID(id) 73 | if err != nil { 74 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": productioncompanie}) 75 | return 76 | } 77 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": productioncompanie}) 78 | }(repo) 79 | } 80 | 81 | func GetProductionCompanieList(c *gin.Context) { 82 | page, errPage := strconv.Atoi(c.Query("page")) 83 | size, errSize := strconv.Atoi(c.Query("size")) 84 | if errPage != nil { 85 | page = 1 86 | } 87 | if errSize != nil { 88 | size = 8 89 | } 90 | db := database.NewDb() 91 | repo := crud.NewRepositoryProductionCompaniesCRUD(db) 92 | func(productioncompanieRepository repository.ProductionCompanieRepository) { 93 | productioncompanies, num, err := productioncompanieRepository.FindAll(page, size) 94 | if err != nil { 95 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": productioncompanies, "num": num}) 96 | return 97 | } 98 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": productioncompanies, "num": num}) 99 | }(repo) 100 | } 101 | 102 | func SearchProductionCompanie(c *gin.Context) { 103 | q := c.Query("q") 104 | if len(q) == 0 { 105 | c.JSON(200, gin.H{"code": 201, "msg": "参数错误!", "data": ""}) 106 | return 107 | } 108 | page, errPage := strconv.Atoi(c.Query("page")) 109 | size, errSize := strconv.Atoi(c.Query("size")) 110 | if errPage != nil { 111 | page = 1 112 | } 113 | if errSize != nil { 114 | size = 8 115 | } 116 | db := database.NewDb() 117 | repo := crud.NewRepositoryProductionCompaniesCRUD(db) 118 | func(productioncompanieRepository repository.ProductionCompanieRepository) { 119 | productioncompanies, num, err := productioncompanieRepository.Search(q, page, size) 120 | if err != nil { 121 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": productioncompanies, "num": num}) 122 | return 123 | } 124 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": productioncompanies, "num": num}) 125 | }(repo) 126 | } 127 | -------------------------------------------------------------------------------- /api/controllers/controllerProductionCountries.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/msterzhang/onelist/api/database" 7 | "github.com/msterzhang/onelist/api/models" 8 | "github.com/msterzhang/onelist/api/repository" 9 | "github.com/msterzhang/onelist/api/repository/crud" 10 | 11 | "github.com/gin-gonic/gin" 12 | ) 13 | 14 | func CreateProductionCountrie(c *gin.Context) { 15 | productioncountrie := models.ProductionCountrie{} 16 | err := c.ShouldBind(&productioncountrie) 17 | if err != nil { 18 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": productioncountrie}) 19 | return 20 | } 21 | db := database.NewDb() 22 | repo := crud.NewRepositoryProductionCountriesCRUD(db) 23 | func(productioncountrieRepository repository.ProductionCountrieRepository) { 24 | productioncountrie, err := productioncountrieRepository.Save(productioncountrie) 25 | if err != nil { 26 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败!", "data": productioncountrie}) 27 | return 28 | } 29 | c.JSON(200, gin.H{"code": 200, "msg": "创建成功!", "data": productioncountrie}) 30 | }(repo) 31 | } 32 | 33 | func DeleteProductionCountrieById(c *gin.Context) { 34 | id := c.Query("id") 35 | db := database.NewDb() 36 | repo := crud.NewRepositoryProductionCountriesCRUD(db) 37 | func(productioncountrieRepository repository.ProductionCountrieRepository) { 38 | productioncountrie, err := productioncountrieRepository.DeleteByID(id) 39 | if err != nil { 40 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": productioncountrie}) 41 | return 42 | } 43 | c.JSON(200, gin.H{"code": 200, "msg": "删除资源成功!", "data": productioncountrie}) 44 | }(repo) 45 | } 46 | 47 | func UpdateProductionCountrieById(c *gin.Context) { 48 | id := c.Query("id") 49 | productioncountrie := models.ProductionCountrie{} 50 | err := c.ShouldBind(&productioncountrie) 51 | if err != nil { 52 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": productioncountrie}) 53 | return 54 | } 55 | db := database.NewDb() 56 | repo := crud.NewRepositoryProductionCountriesCRUD(db) 57 | func(productioncountrieRepository repository.ProductionCountrieRepository) { 58 | productioncountrie, err := productioncountrieRepository.UpdateByID(id, productioncountrie) 59 | if err != nil { 60 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": productioncountrie}) 61 | return 62 | } 63 | c.JSON(200, gin.H{"code": 200, "msg": "更新资源成功!", "data": productioncountrie}) 64 | }(repo) 65 | } 66 | 67 | func GetProductionCountrieById(c *gin.Context) { 68 | id := c.Query("id") 69 | db := database.NewDb() 70 | repo := crud.NewRepositoryProductionCountriesCRUD(db) 71 | func(productioncountrieRepository repository.ProductionCountrieRepository) { 72 | productioncountrie, err := productioncountrieRepository.FindByID(id) 73 | if err != nil { 74 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": productioncountrie}) 75 | return 76 | } 77 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": productioncountrie}) 78 | }(repo) 79 | } 80 | 81 | func GetProductionCountrieList(c *gin.Context) { 82 | page, errPage := strconv.Atoi(c.Query("page")) 83 | size, errSize := strconv.Atoi(c.Query("size")) 84 | if errPage != nil { 85 | page = 1 86 | } 87 | if errSize != nil { 88 | size = 8 89 | } 90 | db := database.NewDb() 91 | repo := crud.NewRepositoryProductionCountriesCRUD(db) 92 | func(productioncountrieRepository repository.ProductionCountrieRepository) { 93 | productioncountries, num, err := productioncountrieRepository.FindAll(page, size) 94 | if err != nil { 95 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": productioncountries, "num": num}) 96 | return 97 | } 98 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": productioncountries, "num": num}) 99 | }(repo) 100 | } 101 | 102 | func SearchProductionCountrie(c *gin.Context) { 103 | q := c.Query("q") 104 | if len(q) == 0 { 105 | c.JSON(200, gin.H{"code": 201, "msg": "参数错误!", "data": ""}) 106 | return 107 | } 108 | page, errPage := strconv.Atoi(c.Query("page")) 109 | size, errSize := strconv.Atoi(c.Query("size")) 110 | if errPage != nil { 111 | page = 1 112 | } 113 | if errSize != nil { 114 | size = 8 115 | } 116 | db := database.NewDb() 117 | repo := crud.NewRepositoryProductionCountriesCRUD(db) 118 | func(productioncountrieRepository repository.ProductionCountrieRepository) { 119 | productioncountries, num, err := productioncountrieRepository.Search(q, page, size) 120 | if err != nil { 121 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": productioncountries, "num": num}) 122 | return 123 | } 124 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": productioncountries, "num": num}) 125 | }(repo) 126 | } 127 | -------------------------------------------------------------------------------- /api/controllers/controllerSeasons.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/msterzhang/onelist/api/database" 7 | "github.com/msterzhang/onelist/api/models" 8 | "github.com/msterzhang/onelist/api/repository" 9 | "github.com/msterzhang/onelist/api/repository/crud" 10 | 11 | "github.com/gin-gonic/gin" 12 | ) 13 | 14 | func CreateSeason(c *gin.Context) { 15 | season := models.Season{} 16 | err := c.ShouldBind(&season) 17 | if err != nil { 18 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": season}) 19 | return 20 | } 21 | db := database.NewDb() 22 | repo := crud.NewRepositorySeasonsCRUD(db) 23 | func(seasonRepository repository.SeasonRepository) { 24 | season, err := seasonRepository.Save(season) 25 | if err != nil { 26 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败!", "data": season}) 27 | return 28 | } 29 | c.JSON(200, gin.H{"code": 200, "msg": "创建成功!", "data": season}) 30 | }(repo) 31 | } 32 | 33 | func DeleteSeasonById(c *gin.Context) { 34 | id := c.Query("id") 35 | db := database.NewDb() 36 | repo := crud.NewRepositorySeasonsCRUD(db) 37 | func(seasonRepository repository.SeasonRepository) { 38 | season, err := seasonRepository.DeleteByID(id) 39 | if err != nil { 40 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": season}) 41 | return 42 | } 43 | c.JSON(200, gin.H{"code": 200, "msg": "删除资源成功!", "data": season}) 44 | }(repo) 45 | } 46 | 47 | func UpdateSeasonById(c *gin.Context) { 48 | id := c.Query("id") 49 | season := models.Season{} 50 | err := c.ShouldBind(&season) 51 | if err != nil { 52 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": season}) 53 | return 54 | } 55 | db := database.NewDb() 56 | repo := crud.NewRepositorySeasonsCRUD(db) 57 | func(seasonRepository repository.SeasonRepository) { 58 | season, err := seasonRepository.UpdateByID(id, season) 59 | if err != nil { 60 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": season}) 61 | return 62 | } 63 | c.JSON(200, gin.H{"code": 200, "msg": "更新资源成功!", "data": season}) 64 | }(repo) 65 | } 66 | 67 | func GetSeasonById(c *gin.Context) { 68 | id := c.Query("id") 69 | db := database.NewDb() 70 | repo := crud.NewRepositorySeasonsCRUD(db) 71 | func(seasonRepository repository.SeasonRepository) { 72 | season, err := seasonRepository.FindByID(id) 73 | if err != nil { 74 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": season}) 75 | return 76 | } 77 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": season}) 78 | }(repo) 79 | } 80 | 81 | func GetSeasonList(c *gin.Context) { 82 | page, errPage := strconv.Atoi(c.Query("page")) 83 | size, errSize := strconv.Atoi(c.Query("size")) 84 | if errPage != nil { 85 | page = 1 86 | } 87 | if errSize != nil { 88 | size = 8 89 | } 90 | db := database.NewDb() 91 | repo := crud.NewRepositorySeasonsCRUD(db) 92 | func(seasonRepository repository.SeasonRepository) { 93 | seasons, num, err := seasonRepository.FindAll(page, size) 94 | if err != nil { 95 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": seasons, "num": num}) 96 | return 97 | } 98 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": seasons, "num": num}) 99 | }(repo) 100 | } 101 | 102 | func SearchSeason(c *gin.Context) { 103 | q := c.Query("q") 104 | if len(q) == 0 { 105 | c.JSON(200, gin.H{"code": 201, "msg": "参数错误!", "data": ""}) 106 | return 107 | } 108 | page, errPage := strconv.Atoi(c.Query("page")) 109 | size, errSize := strconv.Atoi(c.Query("size")) 110 | if errPage != nil { 111 | page = 1 112 | } 113 | if errSize != nil { 114 | size = 8 115 | } 116 | db := database.NewDb() 117 | repo := crud.NewRepositorySeasonsCRUD(db) 118 | func(seasonRepository repository.SeasonRepository) { 119 | seasons, num, err := seasonRepository.Search(q, page, size) 120 | if err != nil { 121 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": seasons, "num": num}) 122 | return 123 | } 124 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": seasons, "num": num}) 125 | }(repo) 126 | } 127 | -------------------------------------------------------------------------------- /api/controllers/controllerSpokenLanguages.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/msterzhang/onelist/api/database" 7 | "github.com/msterzhang/onelist/api/models" 8 | "github.com/msterzhang/onelist/api/repository" 9 | "github.com/msterzhang/onelist/api/repository/crud" 10 | 11 | "github.com/gin-gonic/gin" 12 | ) 13 | 14 | func CreateSpokenLanguage(c *gin.Context) { 15 | spokenlanguage := models.SpokenLanguage{} 16 | err := c.ShouldBind(&spokenlanguage) 17 | if err != nil { 18 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": spokenlanguage}) 19 | return 20 | } 21 | db := database.NewDb() 22 | repo := crud.NewRepositorySpokenLanguagesCRUD(db) 23 | func(spokenlanguageRepository repository.SpokenLanguageRepository) { 24 | spokenlanguage, err := spokenlanguageRepository.Save(spokenlanguage) 25 | if err != nil { 26 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败!", "data": spokenlanguage}) 27 | return 28 | } 29 | c.JSON(200, gin.H{"code": 200, "msg": "创建成功!", "data": spokenlanguage}) 30 | }(repo) 31 | } 32 | 33 | func DeleteSpokenLanguageById(c *gin.Context) { 34 | id := c.Query("id") 35 | db := database.NewDb() 36 | repo := crud.NewRepositorySpokenLanguagesCRUD(db) 37 | func(spokenlanguageRepository repository.SpokenLanguageRepository) { 38 | spokenlanguage, err := spokenlanguageRepository.DeleteByID(id) 39 | if err != nil { 40 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": spokenlanguage}) 41 | return 42 | } 43 | c.JSON(200, gin.H{"code": 200, "msg": "删除资源成功!", "data": spokenlanguage}) 44 | }(repo) 45 | } 46 | 47 | func UpdateSpokenLanguageById(c *gin.Context) { 48 | id := c.Query("id") 49 | spokenlanguage := models.SpokenLanguage{} 50 | err := c.ShouldBind(&spokenlanguage) 51 | if err != nil { 52 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": spokenlanguage}) 53 | return 54 | } 55 | db := database.NewDb() 56 | repo := crud.NewRepositorySpokenLanguagesCRUD(db) 57 | func(spokenlanguageRepository repository.SpokenLanguageRepository) { 58 | spokenlanguage, err := spokenlanguageRepository.UpdateByID(id, spokenlanguage) 59 | if err != nil { 60 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": spokenlanguage}) 61 | return 62 | } 63 | c.JSON(200, gin.H{"code": 200, "msg": "更新资源成功!", "data": spokenlanguage}) 64 | }(repo) 65 | } 66 | 67 | func GetSpokenLanguageById(c *gin.Context) { 68 | id := c.Query("id") 69 | db := database.NewDb() 70 | repo := crud.NewRepositorySpokenLanguagesCRUD(db) 71 | func(spokenlanguageRepository repository.SpokenLanguageRepository) { 72 | spokenlanguage, err := spokenlanguageRepository.FindByID(id) 73 | if err != nil { 74 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": spokenlanguage}) 75 | return 76 | } 77 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": spokenlanguage}) 78 | }(repo) 79 | } 80 | 81 | func GetSpokenLanguageList(c *gin.Context) { 82 | page, errPage := strconv.Atoi(c.Query("page")) 83 | size, errSize := strconv.Atoi(c.Query("size")) 84 | if errPage != nil { 85 | page = 1 86 | } 87 | if errSize != nil { 88 | size = 8 89 | } 90 | db := database.NewDb() 91 | repo := crud.NewRepositorySpokenLanguagesCRUD(db) 92 | func(spokenlanguageRepository repository.SpokenLanguageRepository) { 93 | spokenlanguages, num, err := spokenlanguageRepository.FindAll(page, size) 94 | if err != nil { 95 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": spokenlanguages, "num": num}) 96 | return 97 | } 98 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": spokenlanguages, "num": num}) 99 | }(repo) 100 | } 101 | 102 | func SearchSpokenLanguage(c *gin.Context) { 103 | q := c.Query("q") 104 | if len(q) == 0 { 105 | c.JSON(200, gin.H{"code": 201, "msg": "参数错误!", "data": ""}) 106 | return 107 | } 108 | page, errPage := strconv.Atoi(c.Query("page")) 109 | size, errSize := strconv.Atoi(c.Query("size")) 110 | if errPage != nil { 111 | page = 1 112 | } 113 | if errSize != nil { 114 | size = 8 115 | } 116 | db := database.NewDb() 117 | repo := crud.NewRepositorySpokenLanguagesCRUD(db) 118 | func(spokenlanguageRepository repository.SpokenLanguageRepository) { 119 | spokenlanguages, num, err := spokenlanguageRepository.Search(q, page, size) 120 | if err != nil { 121 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": spokenlanguages, "num": num}) 122 | return 123 | } 124 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": spokenlanguages, "num": num}) 125 | }(repo) 126 | } 127 | -------------------------------------------------------------------------------- /api/controllers/controllerTheCredits.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/msterzhang/onelist/api/database" 7 | "github.com/msterzhang/onelist/api/models" 8 | "github.com/msterzhang/onelist/api/repository" 9 | "github.com/msterzhang/onelist/api/repository/crud" 10 | 11 | "github.com/gin-gonic/gin" 12 | ) 13 | 14 | func CreateTheCredit(c *gin.Context) { 15 | thecredit := models.TheCredit{} 16 | err := c.ShouldBind(&thecredit) 17 | if err != nil { 18 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": thecredit}) 19 | return 20 | } 21 | db := database.NewDb() 22 | repo := crud.NewRepositoryTheCreditsCRUD(db) 23 | func(thecreditRepository repository.TheCreditRepository) { 24 | thecredit, err := thecreditRepository.Save(thecredit) 25 | if err != nil { 26 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败!", "data": thecredit}) 27 | return 28 | } 29 | c.JSON(200, gin.H{"code": 200, "msg": "创建成功!", "data": thecredit}) 30 | }(repo) 31 | } 32 | 33 | func DeleteTheCreditById(c *gin.Context) { 34 | id := c.Query("id") 35 | db := database.NewDb() 36 | repo := crud.NewRepositoryTheCreditsCRUD(db) 37 | func(thecreditRepository repository.TheCreditRepository) { 38 | thecredit, err := thecreditRepository.DeleteByID(id) 39 | if err != nil { 40 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": thecredit}) 41 | return 42 | } 43 | c.JSON(200, gin.H{"code": 200, "msg": "删除资源成功!", "data": thecredit}) 44 | }(repo) 45 | } 46 | 47 | func UpdateTheCreditById(c *gin.Context) { 48 | id := c.Query("id") 49 | thecredit := models.TheCredit{} 50 | err := c.ShouldBind(&thecredit) 51 | if err != nil { 52 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": thecredit}) 53 | return 54 | } 55 | db := database.NewDb() 56 | repo := crud.NewRepositoryTheCreditsCRUD(db) 57 | func(thecreditRepository repository.TheCreditRepository) { 58 | thecredit, err := thecreditRepository.UpdateByID(id, thecredit) 59 | if err != nil { 60 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": thecredit}) 61 | return 62 | } 63 | c.JSON(200, gin.H{"code": 200, "msg": "更新资源成功!", "data": thecredit}) 64 | }(repo) 65 | } 66 | 67 | func GetTheCreditById(c *gin.Context) { 68 | id := c.Query("id") 69 | db := database.NewDb() 70 | repo := crud.NewRepositoryTheCreditsCRUD(db) 71 | func(thecreditRepository repository.TheCreditRepository) { 72 | thecredit, err := thecreditRepository.FindByID(id) 73 | if err != nil { 74 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": thecredit}) 75 | return 76 | } 77 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": thecredit}) 78 | }(repo) 79 | } 80 | 81 | func GetTheCreditList(c *gin.Context) { 82 | page, errPage := strconv.Atoi(c.Query("page")) 83 | size, errSize := strconv.Atoi(c.Query("size")) 84 | if errPage != nil { 85 | page = 1 86 | } 87 | if errSize != nil { 88 | size = 8 89 | } 90 | db := database.NewDb() 91 | repo := crud.NewRepositoryTheCreditsCRUD(db) 92 | func(thecreditRepository repository.TheCreditRepository) { 93 | thecredits, num, err := thecreditRepository.FindAll(page, size) 94 | if err != nil { 95 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": thecredits, "num": num}) 96 | return 97 | } 98 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": thecredits, "num": num}) 99 | }(repo) 100 | } 101 | 102 | func SearchTheCredit(c *gin.Context) { 103 | q := c.Query("q") 104 | if len(q) == 0 { 105 | c.JSON(200, gin.H{"code": 201, "msg": "参数错误!", "data": ""}) 106 | return 107 | } 108 | page, errPage := strconv.Atoi(c.Query("page")) 109 | size, errSize := strconv.Atoi(c.Query("size")) 110 | if errPage != nil { 111 | page = 1 112 | } 113 | if errSize != nil { 114 | size = 8 115 | } 116 | db := database.NewDb() 117 | repo := crud.NewRepositoryTheCreditsCRUD(db) 118 | func(thecreditRepository repository.TheCreditRepository) { 119 | thecredits, num, err := thecreditRepository.Search(q, page, size) 120 | if err != nil { 121 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": thecredits, "num": num}) 122 | return 123 | } 124 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": thecredits, "num": num}) 125 | }(repo) 126 | } 127 | -------------------------------------------------------------------------------- /api/controllers/controllerThePersons.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/msterzhang/onelist/api/database" 7 | "github.com/msterzhang/onelist/api/models" 8 | "github.com/msterzhang/onelist/api/repository" 9 | "github.com/msterzhang/onelist/api/repository/crud" 10 | 11 | "github.com/gin-gonic/gin" 12 | ) 13 | 14 | func CreateThePerson(c *gin.Context) { 15 | theperson := models.ThePerson{} 16 | err := c.ShouldBind(&theperson) 17 | if err != nil { 18 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": theperson}) 19 | return 20 | } 21 | db := database.NewDb() 22 | repo := crud.NewRepositoryThePersonsCRUD(db) 23 | func(thepersonRepository repository.ThePersonRepository) { 24 | theperson, err := thepersonRepository.Save(theperson) 25 | if err != nil { 26 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败!", "data": theperson}) 27 | return 28 | } 29 | c.JSON(200, gin.H{"code": 200, "msg": "创建成功!", "data": theperson}) 30 | }(repo) 31 | } 32 | 33 | func DeleteThePersonById(c *gin.Context) { 34 | id := c.Query("id") 35 | db := database.NewDb() 36 | repo := crud.NewRepositoryThePersonsCRUD(db) 37 | func(thepersonRepository repository.ThePersonRepository) { 38 | theperson, err := thepersonRepository.DeleteByID(id) 39 | if err != nil { 40 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": theperson}) 41 | return 42 | } 43 | c.JSON(200, gin.H{"code": 200, "msg": "删除资源成功!", "data": theperson}) 44 | }(repo) 45 | } 46 | 47 | func UpdateThePersonById(c *gin.Context) { 48 | id := c.Query("id") 49 | theperson := models.ThePerson{} 50 | err := c.ShouldBind(&theperson) 51 | if err != nil { 52 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": theperson}) 53 | return 54 | } 55 | db := database.NewDb() 56 | repo := crud.NewRepositoryThePersonsCRUD(db) 57 | func(thepersonRepository repository.ThePersonRepository) { 58 | theperson, err := thepersonRepository.UpdateByID(id, theperson) 59 | if err != nil { 60 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": theperson}) 61 | return 62 | } 63 | c.JSON(200, gin.H{"code": 200, "msg": "更新资源成功!", "data": theperson}) 64 | }(repo) 65 | } 66 | 67 | func GetThePersonById(c *gin.Context) { 68 | id := c.Query("id") 69 | db := database.NewDb() 70 | repo := crud.NewRepositoryThePersonsCRUD(db) 71 | func(thepersonRepository repository.ThePersonRepository) { 72 | theperson, err := thepersonRepository.FindByID(id) 73 | if err != nil { 74 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": theperson}) 75 | return 76 | } 77 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": theperson}) 78 | }(repo) 79 | } 80 | 81 | func GetThePersonList(c *gin.Context) { 82 | page, errPage := strconv.Atoi(c.Query("page")) 83 | size, errSize := strconv.Atoi(c.Query("size")) 84 | if errPage != nil { 85 | page = 1 86 | } 87 | if errSize != nil { 88 | size = 8 89 | } 90 | db := database.NewDb() 91 | repo := crud.NewRepositoryThePersonsCRUD(db) 92 | func(thepersonRepository repository.ThePersonRepository) { 93 | thepersons, num, err := thepersonRepository.FindAll(page, size) 94 | if err != nil { 95 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": thepersons, "num": num}) 96 | return 97 | } 98 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": thepersons, "num": num}) 99 | }(repo) 100 | } 101 | 102 | func SearchThePerson(c *gin.Context) { 103 | q := c.Query("q") 104 | if len(q) == 0 { 105 | c.JSON(200, gin.H{"code": 201, "msg": "参数错误!", "data": ""}) 106 | return 107 | } 108 | page, errPage := strconv.Atoi(c.Query("page")) 109 | size, errSize := strconv.Atoi(c.Query("size")) 110 | if errPage != nil { 111 | page = 1 112 | } 113 | if errSize != nil { 114 | size = 8 115 | } 116 | db := database.NewDb() 117 | repo := crud.NewRepositoryThePersonsCRUD(db) 118 | func(thepersonRepository repository.ThePersonRepository) { 119 | thepersons, num, err := thepersonRepository.Search(q, page, size) 120 | if err != nil { 121 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": thepersons, "num": num}) 122 | return 123 | } 124 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": thepersons, "num": num}) 125 | }(repo) 126 | } 127 | -------------------------------------------------------------------------------- /api/controllers/controllerTheSeasons.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "sort" 5 | "strconv" 6 | 7 | "github.com/msterzhang/onelist/api/database" 8 | "github.com/msterzhang/onelist/api/models" 9 | "github.com/msterzhang/onelist/api/repository" 10 | "github.com/msterzhang/onelist/api/repository/crud" 11 | 12 | "github.com/gin-gonic/gin" 13 | ) 14 | 15 | func CreateTheSeason(c *gin.Context) { 16 | theseason := models.TheSeason{} 17 | err := c.ShouldBind(&theseason) 18 | if err != nil { 19 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": theseason}) 20 | return 21 | } 22 | db := database.NewDb() 23 | repo := crud.NewRepositoryTheSeasonsCRUD(db) 24 | func(theseasonRepository repository.TheSeasonRepository) { 25 | theseason, err := theseasonRepository.Save(theseason) 26 | if err != nil { 27 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败!", "data": theseason}) 28 | return 29 | } 30 | c.JSON(200, gin.H{"code": 200, "msg": "创建成功!", "data": theseason}) 31 | }(repo) 32 | } 33 | 34 | func DeleteTheSeasonById(c *gin.Context) { 35 | id := c.Query("id") 36 | db := database.NewDb() 37 | repo := crud.NewRepositoryTheSeasonsCRUD(db) 38 | func(theseasonRepository repository.TheSeasonRepository) { 39 | theseason, err := theseasonRepository.DeleteByID(id) 40 | if err != nil { 41 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": theseason}) 42 | return 43 | } 44 | c.JSON(200, gin.H{"code": 200, "msg": "删除资源成功!", "data": theseason}) 45 | }(repo) 46 | } 47 | 48 | func UpdateTheSeasonById(c *gin.Context) { 49 | id := c.Query("id") 50 | theseason := models.TheSeason{} 51 | err := c.ShouldBind(&theseason) 52 | if err != nil { 53 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": theseason}) 54 | return 55 | } 56 | db := database.NewDb() 57 | repo := crud.NewRepositoryTheSeasonsCRUD(db) 58 | func(theseasonRepository repository.TheSeasonRepository) { 59 | theseason, err := theseasonRepository.UpdateByID(id, theseason) 60 | if err != nil { 61 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": theseason}) 62 | return 63 | } 64 | c.JSON(200, gin.H{"code": 200, "msg": "更新资源成功!", "data": theseason}) 65 | }(repo) 66 | } 67 | 68 | func GetTheSeasonById(c *gin.Context) { 69 | id := c.Query("id") 70 | db := database.NewDb() 71 | repo := crud.NewRepositoryTheSeasonsCRUD(db) 72 | func(theseasonRepository repository.TheSeasonRepository) { 73 | theseason, err := theseasonRepository.FindByID(id) 74 | if err != nil { 75 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": theseason}) 76 | return 77 | } 78 | sort.SliceStable(theseason.Episodes, func(i, j int) bool { return theseason.Episodes[i].EpisodeNumber < theseason.Episodes[j].EpisodeNumber }) 79 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": theseason}) 80 | }(repo) 81 | } 82 | 83 | func GetTheSeasonList(c *gin.Context) { 84 | page, errPage := strconv.Atoi(c.Query("page")) 85 | size, errSize := strconv.Atoi(c.Query("size")) 86 | if errPage != nil { 87 | page = 1 88 | } 89 | if errSize != nil { 90 | size = 8 91 | } 92 | db := database.NewDb() 93 | repo := crud.NewRepositoryTheSeasonsCRUD(db) 94 | func(theseasonRepository repository.TheSeasonRepository) { 95 | theseasons, num, err := theseasonRepository.FindAll(page, size) 96 | if err != nil { 97 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": theseasons, "num": num}) 98 | return 99 | } 100 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": theseasons, "num": num}) 101 | }(repo) 102 | } 103 | 104 | func SearchTheSeason(c *gin.Context) { 105 | q := c.Query("q") 106 | if len(q) == 0 { 107 | c.JSON(200, gin.H{"code": 201, "msg": "参数错误!", "data": ""}) 108 | return 109 | } 110 | page, errPage := strconv.Atoi(c.Query("page")) 111 | size, errSize := strconv.Atoi(c.Query("size")) 112 | if errPage != nil { 113 | page = 1 114 | } 115 | if errSize != nil { 116 | size = 8 117 | } 118 | db := database.NewDb() 119 | repo := crud.NewRepositoryTheSeasonsCRUD(db) 120 | func(theseasonRepository repository.TheSeasonRepository) { 121 | theseasons, num, err := theseasonRepository.Search(q, page, size) 122 | if err != nil { 123 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": theseasons, "num": num}) 124 | return 125 | } 126 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": theseasons, "num": num}) 127 | }(repo) 128 | } 129 | -------------------------------------------------------------------------------- /api/controllers/controllerUsers.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/msterzhang/onelist/api/auth" 7 | "github.com/msterzhang/onelist/api/database" 8 | "github.com/msterzhang/onelist/api/models" 9 | "github.com/msterzhang/onelist/api/repository" 10 | "github.com/msterzhang/onelist/api/repository/crud" 11 | 12 | "github.com/gin-gonic/gin" 13 | ) 14 | 15 | func CreateUser(c *gin.Context) { 16 | user := models.User{} 17 | err := c.ShouldBind(&user) 18 | if err != nil { 19 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": user}) 20 | return 21 | } 22 | db := database.NewDb() 23 | repo := crud.NewRepositoryUsersCRUD(db) 24 | func(userRepository repository.UserRepository) { 25 | user, err := userRepository.Save(user) 26 | if err != nil { 27 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败!", "data": user}) 28 | return 29 | } 30 | c.JSON(200, gin.H{"code": 200, "msg": "创建成功!", "data": user}) 31 | }(repo) 32 | } 33 | 34 | func DeleteUserById(c *gin.Context) { 35 | id := c.Query("id") 36 | db := database.NewDb() 37 | repo := crud.NewRepositoryUsersCRUD(db) 38 | func(userRepository repository.UserRepository) { 39 | user, err := userRepository.DeleteByID(id) 40 | if err != nil { 41 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": user}) 42 | return 43 | } 44 | c.JSON(200, gin.H{"code": 200, "msg": "删除资源成功!", "data": user}) 45 | }(repo) 46 | } 47 | 48 | func UpdateUserById(c *gin.Context) { 49 | id := c.Query("id") 50 | user := models.User{} 51 | err := c.ShouldBind(&user) 52 | if err != nil { 53 | c.JSON(200, gin.H{"code": 201, "msg": "创建失败,表单解析出错!", "data": user}) 54 | return 55 | } 56 | db := database.NewDb() 57 | repo := crud.NewRepositoryUsersCRUD(db) 58 | func(userRepository repository.UserRepository) { 59 | user, err := userRepository.UpdateByID(id, user) 60 | if err != nil { 61 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": user}) 62 | return 63 | } 64 | c.JSON(200, gin.H{"code": 200, "msg": "更新资源成功!", "data": user}) 65 | }(repo) 66 | } 67 | 68 | func GetUserById(c *gin.Context) { 69 | id := c.Query("id") 70 | db := database.NewDb() 71 | repo := crud.NewRepositoryUsersCRUD(db) 72 | func(userRepository repository.UserRepository) { 73 | user, err := userRepository.FindByID(id) 74 | if err != nil { 75 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": user}) 76 | return 77 | } 78 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": user}) 79 | }(repo) 80 | } 81 | 82 | func GetUserList(c *gin.Context) { 83 | page, errPage := strconv.Atoi(c.Query("page")) 84 | size, errSize := strconv.Atoi(c.Query("size")) 85 | if errPage != nil { 86 | page = 1 87 | } 88 | if errSize != nil { 89 | size = 8 90 | } 91 | db := database.NewDb() 92 | repo := crud.NewRepositoryUsersCRUD(db) 93 | func(userRepository repository.UserRepository) { 94 | users, num, err := userRepository.FindAll(page, size) 95 | if err != nil { 96 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": users, "num": num}) 97 | return 98 | } 99 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": users, "num": num}) 100 | }(repo) 101 | } 102 | 103 | func SearchUser(c *gin.Context) { 104 | q := c.Query("q") 105 | if len(q) == 0 { 106 | c.JSON(200, gin.H{"code": 201, "msg": "参数错误!", "data": ""}) 107 | return 108 | } 109 | page, errPage := strconv.Atoi(c.Query("page")) 110 | size, errSize := strconv.Atoi(c.Query("size")) 111 | if errPage != nil { 112 | page = 1 113 | } 114 | if errSize != nil { 115 | size = 8 116 | } 117 | db := database.NewDb() 118 | repo := crud.NewRepositoryUsersCRUD(db) 119 | func(userRepository repository.UserRepository) { 120 | users, num, err := userRepository.Search(q, page, size) 121 | if err != nil { 122 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": users, "num": num}) 123 | return 124 | } 125 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": users, "num": num}) 126 | }(repo) 127 | } 128 | 129 | func LoginUser(c *gin.Context) { 130 | user := models.User{} 131 | err := c.ShouldBind(&user) 132 | if err != nil { 133 | c.JSON(200, gin.H{"code": 201, "msg": "解析表单解析出错!", "data": user}) 134 | return 135 | } 136 | user, token, err := auth.Login(user.UserEmail, user.UserPassword) 137 | if err != nil { 138 | c.JSON(200, gin.H{"code": 201, "msg": err.Error(), "data": ""}) 139 | return 140 | } 141 | c.JSON(200, gin.H{"code": 200, "msg": "登录成功!", "data": token, "user": user}) 142 | } 143 | 144 | func UserData(c *gin.Context) { 145 | id := c.GetUint("Id") 146 | db := database.NewDb() 147 | repo := crud.NewRepositoryUsersCRUD(db) 148 | func(userRepository repository.UserRepository) { 149 | user, err := userRepository.FindByID(strconv.Itoa(int(id))) 150 | if err != nil { 151 | c.JSON(200, gin.H{"code": 201, "msg": "没有查询到资源!", "data": user}) 152 | return 153 | } 154 | c.JSON(200, gin.H{"code": 200, "msg": "查询资源成功!", "data": user}) 155 | }(repo) 156 | } 157 | -------------------------------------------------------------------------------- /api/crons/cron.go: -------------------------------------------------------------------------------- 1 | package crons 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/msterzhang/onelist/plugins/watch" 7 | "github.com/robfig/cron/v3" 8 | ) 9 | 10 | var Cron *cron.Cron 11 | 12 | func Run() { 13 | watch.UpdateGalleryImage() 14 | } 15 | 16 | // 5分钟运行一次 17 | func RunFiveM() { 18 | watch.UpdateGalleryImage() 19 | } 20 | 21 | // 6小时运行一次 22 | func RunSixH() { 23 | watch.WatchPath() 24 | } 25 | 26 | // 凌晨两点运行 27 | func DayWork() { 28 | watch.WatchPath() 29 | } 30 | 31 | // 初始化定时任务 32 | func Load() { 33 | go Run() 34 | Cron = cron.New() 35 | _, err := Cron.AddFunc("@every 6h", RunSixH) 36 | if err != nil { 37 | log.Fatal("添加任务失败:" + err.Error()) 38 | } 39 | _, err = Cron.AddFunc("@every 5m", RunFiveM) 40 | if err != nil { 41 | log.Fatal("添加任务失败:" + err.Error()) 42 | } 43 | _, err = Cron.AddFunc("30 2 * * *", DayWork) 44 | if err != nil { 45 | log.Fatalf("添加任务失败:%s", err.Error()) 46 | } 47 | Cron.Start() 48 | } 49 | -------------------------------------------------------------------------------- /api/database/db.go: -------------------------------------------------------------------------------- 1 | package database 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "time" 7 | 8 | "github.com/msterzhang/onelist/config" 9 | 10 | "gorm.io/driver/mysql" 11 | "gorm.io/driver/sqlite" 12 | "gorm.io/gorm" 13 | "gorm.io/gorm/logger" 14 | "gorm.io/gorm/schema" 15 | ) 16 | 17 | var db *gorm.DB 18 | 19 | func NewDb() *gorm.DB { 20 | return db 21 | } 22 | 23 | func InitDb() error { 24 | var err error 25 | dia := sqlite.Open(config.DbName + ".db") 26 | if config.DBDRIVER == "mysql" { 27 | dia = mysql.Open(config.DBURL) 28 | } 29 | db, err = gorm.Open(dia, &gorm.Config{ 30 | NamingStrategy: schema.NamingStrategy{ 31 | SingularTable: true, // 使用单数表名 32 | }, 33 | Logger: logger.New( 34 | log.New(os.Stdout, "\r\n", log.LstdFlags), // io writer(日志输出的目标,前缀和日志包含的内容——译者注) 35 | logger.Config{ 36 | SlowThreshold: time.Second, // 慢 SQL 阈值 37 | LogLevel: logger.Silent, // 日志级别 38 | IgnoreRecordNotFoundError: true, // 忽略ErrRecordNotFound(记录未找到)错误 39 | Colorful: false, // 禁用彩色打印 40 | }, 41 | ), 42 | }) 43 | if err != nil { 44 | log.Fatal("数据库打开失败!") 45 | } 46 | sqlDB, err := db.DB() 47 | if err != nil { 48 | log.Fatal("连接数据库失败!") 49 | } 50 | // SetMaxIdleConns 设置空闲连接池中连接的最大数量 51 | sqlDB.SetMaxIdleConns(10) 52 | 53 | // SetMaxOpenConns 设置打开数据库连接的最大数量。 54 | sqlDB.SetMaxOpenConns(100) 55 | 56 | // SetConnMaxLifetime 设置了连接可复用的最大时间。 57 | sqlDB.SetConnMaxLifetime(time.Hour) 58 | return nil 59 | } 60 | -------------------------------------------------------------------------------- /api/middleware/cors.go: -------------------------------------------------------------------------------- 1 | /* 2 | * @Time : 2022年03月23日 19:19:10 3 | * @Author : root 4 | * @Project : kido 5 | * @File : cors.go 6 | * @Software: GoLand 7 | * @Describe: 8 | */ 9 | package middleware 10 | 11 | import "github.com/gin-gonic/gin" 12 | 13 | func CORSMiddleware() gin.HandlerFunc { 14 | return func(c *gin.Context) { 15 | c.Writer.Header().Set("Access-Control-Allow-Origin", "*") 16 | c.Writer.Header().Set("Access-Control-Allow-Credentials", "true") 17 | c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, token, accept, origin, Cache-Control, X-Requested-With") 18 | c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS, GET, PUT") 19 | 20 | if c.Request.Method == "OPTIONS" { 21 | c.AbortWithStatus(204) 22 | return 23 | } 24 | c.Next() 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /api/models/AddData.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | type AddVideo struct { 4 | TheMovieId int `json:"the_movie_id"` 5 | TheTvId int `json:"the_tv_id"` 6 | GalleryUid string `json:"gallery_uid"` 7 | Path string `json:"path"` 8 | File string `json:"file"` 9 | } 10 | -------------------------------------------------------------------------------- /api/models/AppApi.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | type TheDataIndex struct { 4 | Title string `json:"title"` 5 | GalleryType string `json:"gallery_type"` 6 | GalleryUid string `json:"gallery_uid"` 7 | TheMovieList []TheMovie `json:"the_movie_list"` 8 | TheTvList []TheTv `json:"the_tv_list"` 9 | } 10 | -------------------------------------------------------------------------------- /api/models/Claim.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | "github.com/dgrijalva/jwt-go" 5 | ) 6 | 7 | // Claim is the token payload 8 | type Claim struct { 9 | User User `json:"user"` 10 | jwt.StandardClaims 11 | } 12 | -------------------------------------------------------------------------------- /api/models/Config.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | type Config struct { 4 | Title string `json:"title"` 5 | DownLoadImage string `json:"download_image"` 6 | ImgUrl string `json:"img_url"` 7 | KeyDb string `json:"key_db"` 8 | FaviconicoUrl string `json:"faviconico_url"` 9 | VideoTypes string `json:"video_types"` 10 | } 11 | -------------------------------------------------------------------------------- /api/models/ErrFile.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | "time" 5 | 6 | "gorm.io/gorm" 7 | ) 8 | 9 | // 收集错误文件 10 | type ErrFile struct { 11 | Id uint `json:"id" gorm:"primaryKey"` 12 | GalleryUid string `json:"gallery_uid"` //用于关联电影电视到影库 13 | WorkId uint `json:"work_id"` //用于任务组 14 | File string `json:"file" gorm:"not null;unique"` //文件 15 | ErrMsg string `json:"err_msg"` //错误原因 16 | IsTv bool `json:"is_tv"` //是否为电视 17 | IsOk bool `json:"is_ok"` //是否刮削完毕 18 | CreatedAt time.Time `json:"created_at"` 19 | UpdatedAt time.Time `json:"updated_at"` 20 | } 21 | 22 | func (e *ErrFile) BeforeCreate(tx *gorm.DB) (err error) { 23 | e.CreatedAt = time.Now() 24 | e.UpdatedAt = time.Now() 25 | return 26 | } 27 | 28 | func (e *ErrFile) BeforeUpdate(tx *gorm.DB) (err error) { 29 | e.UpdatedAt = time.Now() 30 | return 31 | } 32 | -------------------------------------------------------------------------------- /api/models/Gallery.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | "time" 5 | 6 | "github.com/google/uuid" 7 | "gorm.io/gorm" 8 | ) 9 | 10 | // 影库 11 | type Gallery struct { 12 | Id uint `json:"id" gorm:"primaryKey"` //ID 13 | Title string `json:"title" gorm:"not null;unique"` //标题 14 | GalleryType string `json:"gallery_type"` //影库类型,电影或者电视 15 | IsTv bool `json:"is_tv"` //影库类型,是否是电视 16 | IsAliOpen bool `json:"is_ali_open"` //挂载盘类型,是否阿里云盘open,支持多清晰度 17 | GalleryUid string `json:"gallery_uid"` //唯一uid 18 | Image string `json:"image"` //图片 19 | IsAlist bool `json:"is_alist"` //是否是alist 20 | AlistHost string `json:"alist_host"` //alist网站域名 21 | AlistUser string `json:"alist_user"` //alist网站管理账号 22 | AlistPwd string `json:"alist_pwd"` //alist网站管理密码 23 | Works []Work `json:"works"` //添加的目录列表 24 | CreatedAt time.Time `json:"created_at"` 25 | UpdatedAt time.Time `json:"updated_at"` 26 | } 27 | 28 | func (g *Gallery) BeforeCreate(tx *gorm.DB) (err error) { 29 | g.GalleryUid = uuid.New().String() 30 | g.CreatedAt = time.Now() 31 | g.UpdatedAt = time.Now() 32 | return 33 | } 34 | 35 | func (g *Gallery) BeforeUpdate(tx *gorm.DB) (err error) { 36 | g.UpdatedAt = time.Now() 37 | return 38 | } 39 | -------------------------------------------------------------------------------- /api/models/Heart.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | "time" 5 | 6 | "gorm.io/gorm" 7 | ) 8 | 9 | // 喜欢 10 | type Heart struct { 11 | Id uint `json:"id" gorm:"primaryKey"` 12 | UserId string `json:"user_id"` 13 | DataType string `json:"data_type"` 14 | DataId int `json:"data_id"` 15 | CreatedAt time.Time `json:"created_at"` 16 | UpdatedAt time.Time `json:"updated_at"` 17 | } 18 | 19 | func (d *Heart) BeforeCreate(tx *gorm.DB) (err error) { 20 | d.CreatedAt = time.Now() 21 | d.UpdatedAt = time.Now() 22 | return 23 | } 24 | 25 | func (d *Heart) BeforeUpdate(tx *gorm.DB) (err error) { 26 | d.UpdatedAt = time.Now() 27 | return 28 | } 29 | -------------------------------------------------------------------------------- /api/models/Played.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | "time" 5 | 6 | "gorm.io/gorm" 7 | ) 8 | 9 | // 已播放 10 | type Played struct { 11 | Id uint `json:"id" gorm:"primaryKey"` 12 | UserId string `json:"user_id"` 13 | DataType string `json:"data_type"` 14 | DataId int `json:"data_id"` 15 | CreatedAt time.Time `json:"created_at"` 16 | UpdatedAt time.Time `json:"updated_at"` 17 | } 18 | 19 | func (d *Played) BeforeCreate(tx *gorm.DB) (err error) { 20 | d.CreatedAt = time.Now() 21 | d.UpdatedAt = time.Now() 22 | return 23 | } 24 | 25 | func (d *Played) BeforeUpdate(tx *gorm.DB) (err error) { 26 | d.UpdatedAt = time.Now() 27 | return 28 | } 29 | -------------------------------------------------------------------------------- /api/models/Star.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | "time" 5 | 6 | "gorm.io/gorm" 7 | ) 8 | 9 | // 收藏 10 | type Star struct { 11 | Id uint `json:"id" gorm:"primaryKey"` 12 | UserId string `json:"user_id"` 13 | DataType string `json:"data_type"` 14 | DataId int `json:"data_id"` 15 | CreatedAt time.Time `json:"created_at"` 16 | UpdatedAt time.Time `json:"updated_at"` 17 | } 18 | 19 | func (d *Star) BeforeCreate(tx *gorm.DB) (err error) { 20 | d.CreatedAt = time.Now() 21 | d.UpdatedAt = time.Now() 22 | return 23 | } 24 | 25 | func (d *Star) BeforeUpdate(tx *gorm.DB) (err error) { 26 | d.UpdatedAt = time.Now() 27 | return 28 | } 29 | -------------------------------------------------------------------------------- /api/models/The.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | // 电影类型 4 | type Genre struct { 5 | ID int `json:"id" gorm:"not null;unique"` 6 | Name string `json:"name"` 7 | TheMovies []TheMovie `json:"the_movies" gorm:"many2many:themovie_Genres;"` 8 | TheTvs []TheTv `json:"the_tvs" gorm:"many2many:thetv_Genres;"` 9 | } 10 | 11 | // 制作公司 12 | type ProductionCompanie struct { 13 | ID int `json:"id" gorm:"not null;unique"` 14 | LogoPath string `json:"logo_path"` 15 | Name string `json:"name"` 16 | OriginCountry string `json:"origin_country"` 17 | TheMovies []TheMovie `json:"the_movies" gorm:"many2many:themovie_ProductionCompanies;"` 18 | TheTvs []TheTv `json:"the_tvs" gorm:"many2many:thetv_ProductionCompanies;"` 19 | } 20 | 21 | // 制作国家 22 | type ProductionCountrie struct { 23 | ID int `json:"id" gorm:"not null;unique"` 24 | Iso31661 string `json:"iso_3166_1"` 25 | Name string `json:"name"` 26 | TheMovies []TheMovie `json:"the_movies" gorm:"many2many:themovie_ProductionCountries;"` 27 | TheTvs []TheTv `json:"the_tvs" gorm:"many2many:thetv_ProductionCountries;"` 28 | } 29 | 30 | // 发布语言 31 | type SpokenLanguage struct { 32 | ID int `json:"id" gorm:"not null;unique"` 33 | EnglishName string `json:"english_name"` 34 | Iso6391 string `json:"iso_639_1"` 35 | Name string `json:"name"` 36 | TheMovies []TheMovie `json:"the_movies" gorm:"many2many:themovie_SpokenLanguages;"` 37 | TheTvs []TheTv `json:"the_tvs" gorm:"many2many:thetv_SpokenLanguages;"` 38 | } 39 | -------------------------------------------------------------------------------- /api/models/TheCredit.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | // 电影演员及制作团队人员 4 | type TheCredit struct { 5 | ID int `json:"id" gorm:"not null;unique"` 6 | TheTvID uint `json:"the_tv_id"` 7 | TheMovieID uint `json:"the_movie_id"` 8 | Cast []CastItem `json:"cast"` 9 | Crew []CrewItem `json:"crew"` 10 | } 11 | 12 | // 主要演员们 13 | type CastItem struct { 14 | ID int `json:"id" gorm:"not null;unique"` 15 | Adult bool `json:"adult"` 16 | Gender int `json:"gender"` 17 | KnownForDepartment string `json:"known_for_department"` 18 | Name string `json:"name"` 19 | OriginalName string `json:"original_name"` 20 | Popularity float64 `json:"popularity"` 21 | ProfilePath string `json:"profile_path"` 22 | CreditID string `json:"credit_id"` 23 | CastID int `json:"cast_id"` 24 | Character string `json:"character"` 25 | Order int `json:"order"` 26 | TheCreditID uint `json:"the_credits_id"` 27 | } 28 | 29 | // 制作团队人员 30 | type CrewItem struct { 31 | ID int `json:"id" gorm:"not null;unique"` 32 | Adult bool `json:"adult"` 33 | Gender int `json:"gender"` 34 | KnownForDepartment string `json:"known_for_department"` 35 | Name string `json:"name"` 36 | OriginalName string `json:"original_name"` 37 | Popularity float64 `json:"popularity"` 38 | ProfilePath string `json:"profile_path"` 39 | CreditID string `json:"credit_id"` 40 | Department string `json:"department"` 41 | Job string `json:"job"` 42 | TheCreditID uint `json:"the_credits_id"` 43 | } 44 | -------------------------------------------------------------------------------- /api/models/TheMovie.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | "time" 5 | 6 | "gorm.io/gorm" 7 | ) 8 | 9 | // 电影剧集 10 | type BelongsToCollection struct { 11 | ID int `json:"id" gorm:"not null;unique"` 12 | Name string `json:"name"` 13 | PosterPath string `json:"poster_path"` 14 | BackdropPath string `json:"backdrop_path"` 15 | TheMovies []TheMovie `json:"the_movies"` 16 | } 17 | 18 | // 电影结构体 19 | type TheMovie struct { 20 | ID int `json:"id" gorm:"not null;unique"` 21 | GalleryUid string `json:"gallery_uid"` 22 | Adult bool `json:"adult"` 23 | BackdropPath string `json:"backdrop_path"` 24 | BelongsToCollection BelongsToCollection `json:"belongs_to_collection"` 25 | Budget int `json:"budget"` 26 | Genres []Genre `json:"genres" gorm:"many2many:themovie_Genres;"` 27 | Homepage string `json:"homepage"` 28 | ImdbID string `json:"imdb_id"` 29 | OriginalLanguage string `json:"original_language"` 30 | OriginalTitle string `json:"original_title"` 31 | Overview string `json:"overview"` 32 | Popularity float64 `json:"popularity"` 33 | PosterPath string `json:"poster_path"` 34 | ProductionCompanies []ProductionCompanie `json:"production_companies" gorm:"many2many:themovie_ProductionCompanies;"` 35 | ProductionCountries []ProductionCountrie `json:"production_countries" gorm:"many2many:themovie_ProductionCountries;"` 36 | ReleaseDate string `json:"release_date"` 37 | Revenue int `json:"revenue"` 38 | Runtime int `json:"runtime"` 39 | SpokenLanguages []SpokenLanguage `json:"spoken_languages" gorm:"many2many:themovie_SpokenLanguages;"` 40 | ThePersons []ThePerson `json:"the_persons" gorm:"many2many:themovie_ThePersons;"` 41 | Status string `json:"status"` 42 | Tagline string `json:"tagline"` 43 | Title string `json:"title"` 44 | Url string `json:"url"` 45 | Video bool `json:"video"` 46 | VoteAverage float64 `json:"vote_average"` 47 | VoteCount int `json:"vote_count"` 48 | TheCredit TheCredit `json:"the_credit"` 49 | BelongsToCollectionID uint `json:"belongs_to_collection_id"` 50 | Star bool `json:"star"` 51 | Heart bool `json:"heart"` 52 | Played bool `json:"played"` 53 | CreatedAt time.Time `json:"created_at"` 54 | UpdatedAt time.Time `json:"updated_at"` 55 | } 56 | 57 | func (m *TheMovie) BeforeCreate(tx *gorm.DB) (err error) { 58 | m.CreatedAt = time.Now() 59 | m.UpdatedAt = time.Now() 60 | return 61 | } 62 | 63 | func (m *TheMovie) BeforeUpdate(tx *gorm.DB) (err error) { 64 | m.UpdatedAt = time.Now() 65 | return 66 | } 67 | -------------------------------------------------------------------------------- /api/models/ThePerson.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | // 演员信息 4 | type ThePerson struct { 5 | ID int `json:"id" gorm:"not null;unique"` 6 | Adult bool `json:"adult"` 7 | Biography string `json:"biography"` 8 | Birthday string `json:"birthday"` 9 | Deathday string `json:"deathday"` 10 | Gender int `json:"gender"` 11 | Homepage string `json:"homepage"` 12 | ImdbID string `json:"imdb_id"` 13 | KnownForDepartment string `json:"known_for_department"` 14 | Name string `json:"name"` 15 | PlaceOfBirth string `json:"place_of_birth"` 16 | Popularity float64 `json:"popularity"` 17 | ProfilePath string `json:"profile_path"` 18 | TheMovies []TheMovie `json:"the_movies" gorm:"many2many:themovie_ThePersons;"` 19 | TheTvs []TheTv `json:"the_tvs" gorm:"many2many:thetv_ThePersons;"` 20 | } 21 | -------------------------------------------------------------------------------- /api/models/TheSeason.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | type Episode struct { 4 | AirDate string `json:"air_date"` 5 | EpisodeNumber int `json:"episode_number"` 6 | ID int `json:"id" gorm:"not null;unique"` 7 | Name string `json:"name"` 8 | Url string `json:"url"` 9 | Overview string `json:"overview"` 10 | ProductionCode string `json:"production_code"` 11 | Runtime int `json:"runtime"` 12 | SeasonNumber int `json:"season_number"` 13 | ShowID int `json:"show_id"` 14 | StillPath string `json:"still_path"` 15 | VoteAverage float64 `json:"vote_average"` 16 | VoteCount int `json:"vote_count"` 17 | TheSeasonID uint `json:"the_season_id"` 18 | } 19 | 20 | type TheSeason struct { 21 | IDS string `json:"_id"` 22 | AirDate string `json:"air_date"` 23 | Episodes []Episode `json:"episodes"` 24 | Name string `json:"name"` 25 | Overview string `json:"overview"` 26 | ID int `json:"id" gorm:"not null;unique"` 27 | PosterPath string `json:"poster_path"` 28 | SeasonNumber int `json:"season_number"` 29 | TheTvID uint `json:"the_tv_id"` 30 | } 31 | -------------------------------------------------------------------------------- /api/models/User.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | "time" 5 | 6 | "github.com/msterzhang/onelist/api/security" 7 | 8 | "github.com/google/uuid" 9 | "gorm.io/gorm" 10 | ) 11 | 12 | type User struct { 13 | Id uint `json:"id" gorm:"primaryKey"` 14 | UserName string `json:"user_name"` 15 | UserId string `json:"user_id"` 16 | UserEmail string `json:"user_email" gorm:"not null;unique"` 17 | UserPassword string `json:"user_password"` 18 | IsAdmin bool `json:"is_admin"` 19 | IsLock bool `json:"is_lock"` 20 | CreatedAt time.Time `json:"created_at"` 21 | UpdatedAt time.Time `json:"updated_at"` 22 | } 23 | 24 | func (u *User) BeforeCreate(tx *gorm.DB) (err error) { 25 | hashPwd, _ := security.Hash(u.UserPassword) 26 | u.UserPassword = hashPwd 27 | u.UserId = uuid.New().String() 28 | u.CreatedAt = time.Now() 29 | u.UpdatedAt = time.Now() 30 | return 31 | } 32 | 33 | func (u *User) BeforeUpdate(tx *gorm.DB) (err error) { 34 | u.UpdatedAt = time.Now() 35 | return 36 | } 37 | -------------------------------------------------------------------------------- /api/models/Work.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | "time" 5 | 6 | "gorm.io/gorm" 7 | ) 8 | 9 | // 刮削任务模型 10 | type Work struct { 11 | Id uint `json:"id" gorm:"primaryKey"` //ID 12 | GalleryID uint `json:"gallery_id"` //关联影库 13 | GalleryUid string `json:"gallery_uid"` //用于关联电影电视到影库 14 | Image string `json:"image"` //图片 15 | Path string `json:"path"` //需要被刮削的目录 16 | FileNumber int `json:"file_number"` //文件总数 17 | Speed int `json:"speed"` //刮削进度 18 | IsOk bool `json:"is_ok"` //是否刮削完毕 19 | Watching bool `json:"watching"` //是否监控目录,每天晚上2点自动扫描 20 | IsRef bool `json:"is_ref"` //是否强制获取alist刷新后的文件列表,不走alist缓存,速度较慢 21 | CreatedAt time.Time `json:"created_at"` 22 | UpdatedAt time.Time `json:"updated_at"` 23 | } 24 | 25 | func (w *Work) BeforeCreate(tx *gorm.DB) (err error) { 26 | w.CreatedAt = time.Now() 27 | w.UpdatedAt = time.Now() 28 | return 29 | } 30 | 31 | func (w *Work) BeforeUpdate(tx *gorm.DB) (err error) { 32 | w.UpdatedAt = time.Now() 33 | return 34 | } 35 | -------------------------------------------------------------------------------- /api/repository/crud/repositoryCastItemsCrud.go: -------------------------------------------------------------------------------- 1 | package crud 2 | 3 | import ( 4 | "errors" 5 | 6 | "github.com/msterzhang/onelist/api/models" 7 | "github.com/msterzhang/onelist/api/utils/channels" 8 | 9 | "gorm.io/gorm" 10 | ) 11 | 12 | // RepositoryCastItemsCRUD is the struct for the CastItem CRUD 13 | type RepositoryCastItemsCRUD struct { 14 | db *gorm.DB 15 | } 16 | 17 | // NewRepositoryCastItemsCRUD returns a new repository with DB connection 18 | func NewRepositoryCastItemsCRUD(db *gorm.DB) *RepositoryCastItemsCRUD { 19 | return &RepositoryCastItemsCRUD{db} 20 | } 21 | 22 | // Save returns a new castitem created or an error 23 | func (r *RepositoryCastItemsCRUD) Save(castitem models.CastItem) (models.CastItem, error) { 24 | var err error 25 | done := make(chan bool) 26 | go func(ch chan<- bool) { 27 | defer close(ch) 28 | err = r.db.Model(&models.CastItem{}).Create(&castitem).Error 29 | if err != nil { 30 | ch <- false 31 | return 32 | } 33 | ch <- true 34 | }(done) 35 | if channels.OK(done) { 36 | return castitem, nil 37 | } 38 | return models.CastItem{}, err 39 | } 40 | 41 | // UpdateByID update castitem from the DB 42 | func (r *RepositoryCastItemsCRUD) UpdateByID(id string, castitem models.CastItem) (int64, error) { 43 | var rs *gorm.DB 44 | done := make(chan bool) 45 | go func(ch chan<- bool) { 46 | defer close(ch) 47 | rs = r.db.Model(&models.CastItem{}).Where("id = ?", id).Select("*").Updates(&castitem) 48 | ch <- true 49 | }(done) 50 | 51 | if channels.OK(done) { 52 | if rs.Error != nil { 53 | return 0, rs.Error 54 | } 55 | 56 | return rs.RowsAffected, nil 57 | } 58 | return 0, rs.Error 59 | } 60 | 61 | // DeleteByID castitem by the id 62 | func (r *RepositoryCastItemsCRUD) DeleteByID(id string) (int64, error) { 63 | var rs *gorm.DB 64 | done := make(chan bool) 65 | go func(ch chan<- bool) { 66 | defer close(ch) 67 | rs = r.db.Model(&models.CastItem{}).Where("id = ?", id).Delete(&models.CastItem{}) 68 | ch <- true 69 | }(done) 70 | 71 | if channels.OK(done) { 72 | if rs.Error != nil { 73 | return 0, rs.Error 74 | } 75 | return rs.RowsAffected, nil 76 | } 77 | return 0, rs.Error 78 | } 79 | 80 | // FindAll returns all the castitems from the DB 81 | func (r *RepositoryCastItemsCRUD) FindAll(page int, size int) ([]models.CastItem, int, error) { 82 | var err error 83 | var num int64 84 | castitems := []models.CastItem{} 85 | done := make(chan bool) 86 | go func(ch chan<- bool) { 87 | defer close(ch) 88 | result := r.db.Model(&models.CastItem{}).Find(&castitems) 89 | result.Count(&num) 90 | err = result.Limit(size).Offset((page - 1) * size).Order("-ID").Scan(&castitems).Error 91 | if err != nil { 92 | ch <- false 93 | return 94 | } 95 | ch <- true 96 | }(done) 97 | if channels.OK(done) { 98 | return castitems, int(num), nil 99 | } 100 | return nil, 0, err 101 | } 102 | 103 | // FindByID return castitem from the DB 104 | func (r *RepositoryCastItemsCRUD) FindByID(id string) (models.CastItem, error) { 105 | var err error 106 | castitem := models.CastItem{} 107 | done := make(chan bool) 108 | go func(ch chan<- bool) { 109 | defer close(ch) 110 | err = r.db.Model(&models.CastItem{}).Where("id = ?", id).Take(&castitem).Error 111 | if err != nil { 112 | ch <- false 113 | return 114 | } 115 | ch <- true 116 | }(done) 117 | if channels.OK(done) { 118 | return castitem, nil 119 | } 120 | 121 | if errors.Is(err, gorm.ErrRecordNotFound) { 122 | return models.CastItem{}, errors.New("castitem Not Found") 123 | } 124 | return models.CastItem{}, err 125 | } 126 | 127 | // Search castitem from the DB 128 | func (r *RepositoryCastItemsCRUD) Search(q string, page int, size int) ([]models.CastItem, int, error) { 129 | var err error 130 | var num int64 131 | castitems := []models.CastItem{} 132 | done := make(chan bool) 133 | go func(ch chan<- bool) { 134 | defer close(ch) 135 | result := r.db.Model(&models.CastItem{}).Where("name LIKE ?", "%"+q+"%") 136 | result.Count(&num) 137 | err = result.Limit(size).Offset((page - 1) * size).Order("-updated_at").Scan(&castitems).Error 138 | if err != nil { 139 | ch <- false 140 | return 141 | } 142 | ch <- true 143 | }(done) 144 | if channels.OK(done) { 145 | return castitems, int(num), nil 146 | } 147 | if errors.Is(err, gorm.ErrRecordNotFound) { 148 | return []models.CastItem{}, 0, errors.New("castitems Not Found") 149 | } 150 | return []models.CastItem{}, 0, err 151 | } 152 | -------------------------------------------------------------------------------- /api/repository/crud/repositoryCrewItemsCrud.go: -------------------------------------------------------------------------------- 1 | package crud 2 | 3 | import ( 4 | "errors" 5 | 6 | "github.com/msterzhang/onelist/api/models" 7 | "github.com/msterzhang/onelist/api/utils/channels" 8 | 9 | "gorm.io/gorm" 10 | ) 11 | 12 | // RepositoryCrewItemsCRUD is the struct for the CrewItem CRUD 13 | type RepositoryCrewItemsCRUD struct { 14 | db *gorm.DB 15 | } 16 | 17 | // NewRepositoryCrewItemsCRUD returns a new repository with DB connection 18 | func NewRepositoryCrewItemsCRUD(db *gorm.DB) *RepositoryCrewItemsCRUD { 19 | return &RepositoryCrewItemsCRUD{db} 20 | } 21 | 22 | // Save returns a new crewitem created or an error 23 | func (r *RepositoryCrewItemsCRUD) Save(crewitem models.CrewItem) (models.CrewItem, error) { 24 | var err error 25 | done := make(chan bool) 26 | go func(ch chan<- bool) { 27 | defer close(ch) 28 | err = r.db.Model(&models.CrewItem{}).Create(&crewitem).Error 29 | if err != nil { 30 | ch <- false 31 | return 32 | } 33 | ch <- true 34 | }(done) 35 | if channels.OK(done) { 36 | return crewitem, nil 37 | } 38 | return models.CrewItem{}, err 39 | } 40 | 41 | // UpdateByID update crewitem from the DB 42 | func (r *RepositoryCrewItemsCRUD) UpdateByID(id string, crewitem models.CrewItem) (int64, error) { 43 | var rs *gorm.DB 44 | done := make(chan bool) 45 | go func(ch chan<- bool) { 46 | defer close(ch) 47 | rs = r.db.Model(&models.CrewItem{}).Where("id = ?", id).Select("*").Updates(&crewitem) 48 | ch <- true 49 | }(done) 50 | 51 | if channels.OK(done) { 52 | if rs.Error != nil { 53 | return 0, rs.Error 54 | } 55 | 56 | return rs.RowsAffected, nil 57 | } 58 | return 0, rs.Error 59 | } 60 | 61 | // DeleteByID crewitem by the id 62 | func (r *RepositoryCrewItemsCRUD) DeleteByID(id string) (int64, error) { 63 | var rs *gorm.DB 64 | done := make(chan bool) 65 | go func(ch chan<- bool) { 66 | defer close(ch) 67 | rs = r.db.Model(&models.CrewItem{}).Where("id = ?", id).Delete(&models.CrewItem{}) 68 | ch <- true 69 | }(done) 70 | 71 | if channels.OK(done) { 72 | if rs.Error != nil { 73 | return 0, rs.Error 74 | } 75 | return rs.RowsAffected, nil 76 | } 77 | return 0, rs.Error 78 | } 79 | 80 | // FindAll returns all the crewitems from the DB 81 | func (r *RepositoryCrewItemsCRUD) FindAll(page int, size int) ([]models.CrewItem, int, error) { 82 | var err error 83 | var num int64 84 | crewitems := []models.CrewItem{} 85 | done := make(chan bool) 86 | go func(ch chan<- bool) { 87 | defer close(ch) 88 | result := r.db.Model(&models.CrewItem{}).Find(&crewitems) 89 | result.Count(&num) 90 | err = result.Limit(size).Offset((page - 1) * size).Order("-ID").Scan(&crewitems).Error 91 | if err != nil { 92 | ch <- false 93 | return 94 | } 95 | ch <- true 96 | }(done) 97 | if channels.OK(done) { 98 | return crewitems, int(num), nil 99 | } 100 | return nil, 0, err 101 | } 102 | 103 | // FindByID return crewitem from the DB 104 | func (r *RepositoryCrewItemsCRUD) FindByID(id string) (models.CrewItem, error) { 105 | var err error 106 | crewitem := models.CrewItem{} 107 | done := make(chan bool) 108 | go func(ch chan<- bool) { 109 | defer close(ch) 110 | err = r.db.Model(&models.CrewItem{}).Where("id = ?", id).Take(&crewitem).Error 111 | if err != nil { 112 | ch <- false 113 | return 114 | } 115 | ch <- true 116 | }(done) 117 | if channels.OK(done) { 118 | return crewitem, nil 119 | } 120 | 121 | if errors.Is(err, gorm.ErrRecordNotFound) { 122 | return models.CrewItem{}, errors.New("crewitem Not Found") 123 | } 124 | return models.CrewItem{}, err 125 | } 126 | 127 | // Search crewitem from the DB 128 | func (r *RepositoryCrewItemsCRUD) Search(q string, page int, size int) ([]models.CrewItem, int, error) { 129 | var err error 130 | var num int64 131 | crewitems := []models.CrewItem{} 132 | done := make(chan bool) 133 | go func(ch chan<- bool) { 134 | defer close(ch) 135 | result := r.db.Model(&models.CrewItem{}).Where("name LIKE ?", "%"+q+"%") 136 | result.Count(&num) 137 | err = result.Limit(size).Offset((page - 1) * size).Order("-updated_at").Scan(&crewitems).Error 138 | if err != nil { 139 | ch <- false 140 | return 141 | } 142 | ch <- true 143 | }(done) 144 | if channels.OK(done) { 145 | return crewitems, int(num), nil 146 | } 147 | if errors.Is(err, gorm.ErrRecordNotFound) { 148 | return []models.CrewItem{}, 0, errors.New("crewitems Not Found") 149 | } 150 | return []models.CrewItem{}, 0, err 151 | } 152 | -------------------------------------------------------------------------------- /api/repository/crud/repositoryEpisodesCrud.go: -------------------------------------------------------------------------------- 1 | package crud 2 | 3 | import ( 4 | "errors" 5 | 6 | "github.com/msterzhang/onelist/api/models" 7 | "github.com/msterzhang/onelist/api/utils/channels" 8 | 9 | "gorm.io/gorm" 10 | ) 11 | 12 | // RepositoryEpisodesCRUD is the struct for the Episode CRUD 13 | type RepositoryEpisodesCRUD struct { 14 | db *gorm.DB 15 | } 16 | 17 | // NewRepositoryEpisodesCRUD returns a new repository with DB connection 18 | func NewRepositoryEpisodesCRUD(db *gorm.DB) *RepositoryEpisodesCRUD { 19 | return &RepositoryEpisodesCRUD{db} 20 | } 21 | 22 | // Save returns a new episode created or an error 23 | func (r *RepositoryEpisodesCRUD) Save(episode models.Episode) (models.Episode, error) { 24 | var err error 25 | done := make(chan bool) 26 | go func(ch chan<- bool) { 27 | defer close(ch) 28 | err = r.db.Model(&models.Episode{}).Create(&episode).Error 29 | if err != nil { 30 | ch <- false 31 | return 32 | } 33 | ch <- true 34 | }(done) 35 | if channels.OK(done) { 36 | return episode, nil 37 | } 38 | return models.Episode{}, err 39 | } 40 | 41 | // UpdateByID update episode from the DB 42 | func (r *RepositoryEpisodesCRUD) UpdateByID(id string, episode models.Episode) (int64, error) { 43 | var rs *gorm.DB 44 | done := make(chan bool) 45 | go func(ch chan<- bool) { 46 | defer close(ch) 47 | rs = r.db.Model(&models.Episode{}).Where("id = ?", id).Select("*").Updates(&episode) 48 | ch <- true 49 | }(done) 50 | 51 | if channels.OK(done) { 52 | if rs.Error != nil { 53 | return 0, rs.Error 54 | } 55 | 56 | return rs.RowsAffected, nil 57 | } 58 | return 0, rs.Error 59 | } 60 | 61 | // DeleteByID episode by the id 62 | func (r *RepositoryEpisodesCRUD) DeleteByID(id string) (int64, error) { 63 | var rs *gorm.DB 64 | done := make(chan bool) 65 | go func(ch chan<- bool) { 66 | defer close(ch) 67 | rs = r.db.Model(&models.Episode{}).Where("id = ?", id).Delete(&models.Episode{}) 68 | ch <- true 69 | }(done) 70 | 71 | if channels.OK(done) { 72 | if rs.Error != nil { 73 | return 0, rs.Error 74 | } 75 | return rs.RowsAffected, nil 76 | } 77 | return 0, rs.Error 78 | } 79 | 80 | // FindAll returns all the episodes from the DB 81 | func (r *RepositoryEpisodesCRUD) FindAll(page int, size int) ([]models.Episode, int, error) { 82 | var err error 83 | var num int64 84 | episodes := []models.Episode{} 85 | done := make(chan bool) 86 | go func(ch chan<- bool) { 87 | defer close(ch) 88 | result := r.db.Model(&models.Episode{}).Find(&episodes) 89 | result.Count(&num) 90 | err = result.Limit(size).Offset((page - 1) * size).Order("-ID").Scan(&episodes).Error 91 | if err != nil { 92 | ch <- false 93 | return 94 | } 95 | ch <- true 96 | }(done) 97 | if channels.OK(done) { 98 | return episodes, int(num), nil 99 | } 100 | return nil, 0, err 101 | } 102 | 103 | // FindByID return episode from the DB 104 | func (r *RepositoryEpisodesCRUD) FindByID(id string) (models.Episode, error) { 105 | var err error 106 | episode := models.Episode{} 107 | done := make(chan bool) 108 | go func(ch chan<- bool) { 109 | defer close(ch) 110 | err = r.db.Model(&models.Episode{}).Where("id = ?", id).Take(&episode).Error 111 | if err != nil { 112 | ch <- false 113 | return 114 | } 115 | ch <- true 116 | }(done) 117 | if channels.OK(done) { 118 | return episode, nil 119 | } 120 | 121 | if errors.Is(err, gorm.ErrRecordNotFound) { 122 | return models.Episode{}, errors.New("episode Not Found") 123 | } 124 | return models.Episode{}, err 125 | } 126 | 127 | // Search episode from the DB 128 | func (r *RepositoryEpisodesCRUD) Search(q string, page int, size int) ([]models.Episode, int, error) { 129 | var err error 130 | var num int64 131 | episodes := []models.Episode{} 132 | done := make(chan bool) 133 | go func(ch chan<- bool) { 134 | defer close(ch) 135 | result := r.db.Model(&models.Episode{}).Where("name LIKE ?", "%"+q+"%") 136 | result.Count(&num) 137 | err = result.Limit(size).Offset((page - 1) * size).Order("-updated_at").Scan(&episodes).Error 138 | if err != nil { 139 | ch <- false 140 | return 141 | } 142 | ch <- true 143 | }(done) 144 | if channels.OK(done) { 145 | return episodes, int(num), nil 146 | } 147 | if errors.Is(err, gorm.ErrRecordNotFound) { 148 | return []models.Episode{}, 0, errors.New("episodes Not Found") 149 | } 150 | return []models.Episode{}, 0, err 151 | } 152 | -------------------------------------------------------------------------------- /api/repository/crud/repositoryLastEpisodeToAirsCrud.go: -------------------------------------------------------------------------------- 1 | package crud 2 | 3 | import ( 4 | "errors" 5 | 6 | "github.com/msterzhang/onelist/api/models" 7 | "github.com/msterzhang/onelist/api/utils/channels" 8 | 9 | "gorm.io/gorm" 10 | ) 11 | 12 | // RepositoryLastEpisodeToAirsCRUD is the struct for the LastEpisodeToAir CRUD 13 | type RepositoryLastEpisodeToAirsCRUD struct { 14 | db *gorm.DB 15 | } 16 | 17 | // NewRepositoryLastEpisodeToAirsCRUD returns a new repository with DB connection 18 | func NewRepositoryLastEpisodeToAirsCRUD(db *gorm.DB) *RepositoryLastEpisodeToAirsCRUD { 19 | return &RepositoryLastEpisodeToAirsCRUD{db} 20 | } 21 | 22 | // Save returns a new lastepisodetoair created or an error 23 | func (r *RepositoryLastEpisodeToAirsCRUD) Save(lastepisodetoair models.LastEpisodeToAir) (models.LastEpisodeToAir, error) { 24 | var err error 25 | done := make(chan bool) 26 | go func(ch chan<- bool) { 27 | defer close(ch) 28 | err = r.db.Model(&models.LastEpisodeToAir{}).Create(&lastepisodetoair).Error 29 | if err != nil { 30 | ch <- false 31 | return 32 | } 33 | ch <- true 34 | }(done) 35 | if channels.OK(done) { 36 | return lastepisodetoair, nil 37 | } 38 | return models.LastEpisodeToAir{}, err 39 | } 40 | 41 | // UpdateByID update lastepisodetoair from the DB 42 | func (r *RepositoryLastEpisodeToAirsCRUD) UpdateByID(id string, lastepisodetoair models.LastEpisodeToAir) (int64, error) { 43 | var rs *gorm.DB 44 | done := make(chan bool) 45 | go func(ch chan<- bool) { 46 | defer close(ch) 47 | rs = r.db.Model(&models.LastEpisodeToAir{}).Where("id = ?", id).Select("*").Updates(&lastepisodetoair) 48 | ch <- true 49 | }(done) 50 | 51 | if channels.OK(done) { 52 | if rs.Error != nil { 53 | return 0, rs.Error 54 | } 55 | 56 | return rs.RowsAffected, nil 57 | } 58 | return 0, rs.Error 59 | } 60 | 61 | // DeleteByID lastepisodetoair by the id 62 | func (r *RepositoryLastEpisodeToAirsCRUD) DeleteByID(id string) (int64, error) { 63 | var rs *gorm.DB 64 | done := make(chan bool) 65 | go func(ch chan<- bool) { 66 | defer close(ch) 67 | rs = r.db.Model(&models.LastEpisodeToAir{}).Where("id = ?", id).Delete(&models.LastEpisodeToAir{}) 68 | ch <- true 69 | }(done) 70 | 71 | if channels.OK(done) { 72 | if rs.Error != nil { 73 | return 0, rs.Error 74 | } 75 | return rs.RowsAffected, nil 76 | } 77 | return 0, rs.Error 78 | } 79 | 80 | // FindAll returns all the lastepisodetoairs from the DB 81 | func (r *RepositoryLastEpisodeToAirsCRUD) FindAll(page int, size int) ([]models.LastEpisodeToAir, int, error) { 82 | var err error 83 | var num int64 84 | lastepisodetoairs := []models.LastEpisodeToAir{} 85 | done := make(chan bool) 86 | go func(ch chan<- bool) { 87 | defer close(ch) 88 | result := r.db.Model(&models.LastEpisodeToAir{}).Find(&lastepisodetoairs) 89 | result.Count(&num) 90 | err = result.Limit(size).Offset((page - 1) * size).Order("-ID").Scan(&lastepisodetoairs).Error 91 | if err != nil { 92 | ch <- false 93 | return 94 | } 95 | ch <- true 96 | }(done) 97 | if channels.OK(done) { 98 | return lastepisodetoairs, int(num), nil 99 | } 100 | return nil, 0, err 101 | } 102 | 103 | // FindByID return lastepisodetoair from the DB 104 | func (r *RepositoryLastEpisodeToAirsCRUD) FindByID(id string) (models.LastEpisodeToAir, error) { 105 | var err error 106 | lastepisodetoair := models.LastEpisodeToAir{} 107 | done := make(chan bool) 108 | go func(ch chan<- bool) { 109 | defer close(ch) 110 | err = r.db.Model(&models.LastEpisodeToAir{}).Where("id = ?", id).Take(&lastepisodetoair).Error 111 | if err != nil { 112 | ch <- false 113 | return 114 | } 115 | ch <- true 116 | }(done) 117 | if channels.OK(done) { 118 | return lastepisodetoair, nil 119 | } 120 | 121 | if errors.Is(err, gorm.ErrRecordNotFound) { 122 | return models.LastEpisodeToAir{}, errors.New("lastepisodetoair Not Found") 123 | } 124 | return models.LastEpisodeToAir{}, err 125 | } 126 | 127 | // Search lastepisodetoair from the DB 128 | func (r *RepositoryLastEpisodeToAirsCRUD) Search(q string, page int, size int) ([]models.LastEpisodeToAir, int, error) { 129 | var err error 130 | var num int64 131 | lastepisodetoairs := []models.LastEpisodeToAir{} 132 | done := make(chan bool) 133 | go func(ch chan<- bool) { 134 | defer close(ch) 135 | result := r.db.Model(&models.LastEpisodeToAir{}).Where("name LIKE ?", "%"+q+"%") 136 | result.Count(&num) 137 | err = result.Limit(size).Offset((page - 1) * size).Order("-updated_at").Scan(&lastepisodetoairs).Error 138 | if err != nil { 139 | ch <- false 140 | return 141 | } 142 | ch <- true 143 | }(done) 144 | if channels.OK(done) { 145 | return lastepisodetoairs, int(num), nil 146 | } 147 | if errors.Is(err, gorm.ErrRecordNotFound) { 148 | return []models.LastEpisodeToAir{}, 0, errors.New("lastepisodetoairs Not Found") 149 | } 150 | return []models.LastEpisodeToAir{}, 0, err 151 | } 152 | -------------------------------------------------------------------------------- /api/repository/crud/repositoryNetworkssCrud.go: -------------------------------------------------------------------------------- 1 | package crud 2 | 3 | import ( 4 | "errors" 5 | 6 | "github.com/msterzhang/onelist/api/models" 7 | "github.com/msterzhang/onelist/api/utils/channels" 8 | 9 | "gorm.io/gorm" 10 | ) 11 | 12 | // RepositoryNetworkssCRUD is the struct for the Networks CRUD 13 | type RepositoryNetworkssCRUD struct { 14 | db *gorm.DB 15 | } 16 | 17 | // NewRepositoryNetworkssCRUD returns a new repository with DB connection 18 | func NewRepositoryNetworkssCRUD(db *gorm.DB) *RepositoryNetworkssCRUD { 19 | return &RepositoryNetworkssCRUD{db} 20 | } 21 | 22 | // Save returns a new networks created or an error 23 | func (r *RepositoryNetworkssCRUD) Save(networks models.Networks) (models.Networks, error) { 24 | var err error 25 | done := make(chan bool) 26 | go func(ch chan<- bool) { 27 | defer close(ch) 28 | err = r.db.Model(&models.Networks{}).Create(&networks).Error 29 | if err != nil { 30 | ch <- false 31 | return 32 | } 33 | ch <- true 34 | }(done) 35 | if channels.OK(done) { 36 | return networks, nil 37 | } 38 | return models.Networks{}, err 39 | } 40 | 41 | // UpdateByID update networks from the DB 42 | func (r *RepositoryNetworkssCRUD) UpdateByID(id string, networks models.Networks) (int64, error) { 43 | var rs *gorm.DB 44 | done := make(chan bool) 45 | go func(ch chan<- bool) { 46 | defer close(ch) 47 | rs = r.db.Model(&models.Networks{}).Where("id = ?", id).Select("*").Updates(&networks) 48 | ch <- true 49 | }(done) 50 | 51 | if channels.OK(done) { 52 | if rs.Error != nil { 53 | return 0, rs.Error 54 | } 55 | 56 | return rs.RowsAffected, nil 57 | } 58 | return 0, rs.Error 59 | } 60 | 61 | // DeleteByID networks by the id 62 | func (r *RepositoryNetworkssCRUD) DeleteByID(id string) (int64, error) { 63 | var rs *gorm.DB 64 | done := make(chan bool) 65 | go func(ch chan<- bool) { 66 | defer close(ch) 67 | rs = r.db.Model(&models.Networks{}).Where("id = ?", id).Delete(&models.Networks{}) 68 | ch <- true 69 | }(done) 70 | 71 | if channels.OK(done) { 72 | if rs.Error != nil { 73 | return 0, rs.Error 74 | } 75 | return rs.RowsAffected, nil 76 | } 77 | return 0, rs.Error 78 | } 79 | 80 | // FindAll returns all the networkss from the DB 81 | func (r *RepositoryNetworkssCRUD) FindAll(page int, size int) ([]models.Networks, int, error) { 82 | var err error 83 | var num int64 84 | networkss := []models.Networks{} 85 | done := make(chan bool) 86 | go func(ch chan<- bool) { 87 | defer close(ch) 88 | result := r.db.Model(&models.Networks{}).Find(&networkss) 89 | result.Count(&num) 90 | err = result.Limit(size).Offset((page - 1) * size).Order("-ID").Scan(&networkss).Error 91 | if err != nil { 92 | ch <- false 93 | return 94 | } 95 | ch <- true 96 | }(done) 97 | if channels.OK(done) { 98 | return networkss, int(num), nil 99 | } 100 | return nil, 0, err 101 | } 102 | 103 | // FindByID return networks from the DB 104 | func (r *RepositoryNetworkssCRUD) FindByID(id string) (models.Networks, error) { 105 | var err error 106 | networks := models.Networks{} 107 | done := make(chan bool) 108 | go func(ch chan<- bool) { 109 | defer close(ch) 110 | err = r.db.Model(&models.Networks{}).Where("id = ?", id).Take(&networks).Error 111 | if err != nil { 112 | ch <- false 113 | return 114 | } 115 | ch <- true 116 | }(done) 117 | if channels.OK(done) { 118 | return networks, nil 119 | } 120 | 121 | if errors.Is(err, gorm.ErrRecordNotFound) { 122 | return models.Networks{}, errors.New("networks Not Found") 123 | } 124 | return models.Networks{}, err 125 | } 126 | 127 | // Search networks from the DB 128 | func (r *RepositoryNetworkssCRUD) Search(q string, page int, size int) ([]models.Networks, int, error) { 129 | var err error 130 | var num int64 131 | networkss := []models.Networks{} 132 | done := make(chan bool) 133 | go func(ch chan<- bool) { 134 | defer close(ch) 135 | result := r.db.Model(&models.Networks{}).Where("name LIKE ?", "%"+q+"%") 136 | result.Count(&num) 137 | err = result.Limit(size).Offset((page - 1) * size).Order("-updated_at").Scan(&networkss).Error 138 | if err != nil { 139 | ch <- false 140 | return 141 | } 142 | ch <- true 143 | }(done) 144 | if channels.OK(done) { 145 | return networkss, int(num), nil 146 | } 147 | if errors.Is(err, gorm.ErrRecordNotFound) { 148 | return []models.Networks{}, 0, errors.New("networkss Not Found") 149 | } 150 | return []models.Networks{}, 0, err 151 | } 152 | -------------------------------------------------------------------------------- /api/repository/crud/repositoryNextEpisodeToAirsCrud.go: -------------------------------------------------------------------------------- 1 | package crud 2 | 3 | import ( 4 | "errors" 5 | 6 | "github.com/msterzhang/onelist/api/models" 7 | "github.com/msterzhang/onelist/api/utils/channels" 8 | 9 | "gorm.io/gorm" 10 | ) 11 | 12 | // RepositoryNextEpisodeToAirsCRUD is the struct for the NextEpisodeToAir CRUD 13 | type RepositoryNextEpisodeToAirsCRUD struct { 14 | db *gorm.DB 15 | } 16 | 17 | // NewRepositoryNextEpisodeToAirsCRUD returns a new repository with DB connection 18 | func NewRepositoryNextEpisodeToAirsCRUD(db *gorm.DB) *RepositoryNextEpisodeToAirsCRUD { 19 | return &RepositoryNextEpisodeToAirsCRUD{db} 20 | } 21 | 22 | // Save returns a new nextepisodetoair created or an error 23 | func (r *RepositoryNextEpisodeToAirsCRUD) Save(nextepisodetoair models.NextEpisodeToAir) (models.NextEpisodeToAir, error) { 24 | var err error 25 | done := make(chan bool) 26 | go func(ch chan<- bool) { 27 | defer close(ch) 28 | err = r.db.Model(&models.NextEpisodeToAir{}).Create(&nextepisodetoair).Error 29 | if err != nil { 30 | ch <- false 31 | return 32 | } 33 | ch <- true 34 | }(done) 35 | if channels.OK(done) { 36 | return nextepisodetoair, nil 37 | } 38 | return models.NextEpisodeToAir{}, err 39 | } 40 | 41 | // UpdateByID update nextepisodetoair from the DB 42 | func (r *RepositoryNextEpisodeToAirsCRUD) UpdateByID(id string, nextepisodetoair models.NextEpisodeToAir) (int64, error) { 43 | var rs *gorm.DB 44 | done := make(chan bool) 45 | go func(ch chan<- bool) { 46 | defer close(ch) 47 | rs = r.db.Model(&models.NextEpisodeToAir{}).Where("id = ?", id).Select("*").Updates(&nextepisodetoair) 48 | ch <- true 49 | }(done) 50 | 51 | if channels.OK(done) { 52 | if rs.Error != nil { 53 | return 0, rs.Error 54 | } 55 | 56 | return rs.RowsAffected, nil 57 | } 58 | return 0, rs.Error 59 | } 60 | 61 | // DeleteByID nextepisodetoair by the id 62 | func (r *RepositoryNextEpisodeToAirsCRUD) DeleteByID(id string) (int64, error) { 63 | var rs *gorm.DB 64 | done := make(chan bool) 65 | go func(ch chan<- bool) { 66 | defer close(ch) 67 | rs = r.db.Model(&models.NextEpisodeToAir{}).Where("id = ?", id).Delete(&models.NextEpisodeToAir{}) 68 | ch <- true 69 | }(done) 70 | 71 | if channels.OK(done) { 72 | if rs.Error != nil { 73 | return 0, rs.Error 74 | } 75 | return rs.RowsAffected, nil 76 | } 77 | return 0, rs.Error 78 | } 79 | 80 | // FindAll returns all the nextepisodetoairs from the DB 81 | func (r *RepositoryNextEpisodeToAirsCRUD) FindAll(page int, size int) ([]models.NextEpisodeToAir, int, error) { 82 | var err error 83 | var num int64 84 | nextepisodetoairs := []models.NextEpisodeToAir{} 85 | done := make(chan bool) 86 | go func(ch chan<- bool) { 87 | defer close(ch) 88 | result := r.db.Model(&models.NextEpisodeToAir{}).Find(&nextepisodetoairs) 89 | result.Count(&num) 90 | err = result.Limit(size).Offset((page - 1) * size).Order("-ID").Scan(&nextepisodetoairs).Error 91 | if err != nil { 92 | ch <- false 93 | return 94 | } 95 | ch <- true 96 | }(done) 97 | if channels.OK(done) { 98 | return nextepisodetoairs, int(num), nil 99 | } 100 | return nil, 0, err 101 | } 102 | 103 | // FindByID return nextepisodetoair from the DB 104 | func (r *RepositoryNextEpisodeToAirsCRUD) FindByID(id string) (models.NextEpisodeToAir, error) { 105 | var err error 106 | nextepisodetoair := models.NextEpisodeToAir{} 107 | done := make(chan bool) 108 | go func(ch chan<- bool) { 109 | defer close(ch) 110 | err = r.db.Model(&models.NextEpisodeToAir{}).Where("id = ?", id).Take(&nextepisodetoair).Error 111 | if err != nil { 112 | ch <- false 113 | return 114 | } 115 | ch <- true 116 | }(done) 117 | if channels.OK(done) { 118 | return nextepisodetoair, nil 119 | } 120 | 121 | if errors.Is(err, gorm.ErrRecordNotFound) { 122 | return models.NextEpisodeToAir{}, errors.New("nextepisodetoair Not Found") 123 | } 124 | return models.NextEpisodeToAir{}, err 125 | } 126 | 127 | // Search nextepisodetoair from the DB 128 | func (r *RepositoryNextEpisodeToAirsCRUD) Search(q string, page int, size int) ([]models.NextEpisodeToAir, int, error) { 129 | var err error 130 | var num int64 131 | nextepisodetoairs := []models.NextEpisodeToAir{} 132 | done := make(chan bool) 133 | go func(ch chan<- bool) { 134 | defer close(ch) 135 | result := r.db.Model(&models.NextEpisodeToAir{}).Where("name LIKE ?", "%"+q+"%") 136 | result.Count(&num) 137 | err = result.Limit(size).Offset((page - 1) * size).Order("-updated_at").Scan(&nextepisodetoairs).Error 138 | if err != nil { 139 | ch <- false 140 | return 141 | } 142 | ch <- true 143 | }(done) 144 | if channels.OK(done) { 145 | return nextepisodetoairs, int(num), nil 146 | } 147 | if errors.Is(err, gorm.ErrRecordNotFound) { 148 | return []models.NextEpisodeToAir{}, 0, errors.New("nextepisodetoairs Not Found") 149 | } 150 | return []models.NextEpisodeToAir{}, 0, err 151 | } 152 | -------------------------------------------------------------------------------- /api/repository/crud/repositorySeasonsCrud.go: -------------------------------------------------------------------------------- 1 | package crud 2 | 3 | import ( 4 | "errors" 5 | 6 | "github.com/msterzhang/onelist/api/models" 7 | "github.com/msterzhang/onelist/api/utils/channels" 8 | 9 | "gorm.io/gorm" 10 | ) 11 | 12 | // RepositorySeasonsCRUD is the struct for the Season CRUD 13 | type RepositorySeasonsCRUD struct { 14 | db *gorm.DB 15 | } 16 | 17 | // NewRepositorySeasonsCRUD returns a new repository with DB connection 18 | func NewRepositorySeasonsCRUD(db *gorm.DB) *RepositorySeasonsCRUD { 19 | return &RepositorySeasonsCRUD{db} 20 | } 21 | 22 | // Save returns a new season created or an error 23 | func (r *RepositorySeasonsCRUD) Save(season models.Season) (models.Season, error) { 24 | var err error 25 | done := make(chan bool) 26 | go func(ch chan<- bool) { 27 | defer close(ch) 28 | err = r.db.Model(&models.Season{}).Create(&season).Error 29 | if err != nil { 30 | ch <- false 31 | return 32 | } 33 | ch <- true 34 | }(done) 35 | if channels.OK(done) { 36 | return season, nil 37 | } 38 | return models.Season{}, err 39 | } 40 | 41 | // UpdateByID update season from the DB 42 | func (r *RepositorySeasonsCRUD) UpdateByID(id string, season models.Season) (int64, error) { 43 | var rs *gorm.DB 44 | done := make(chan bool) 45 | go func(ch chan<- bool) { 46 | defer close(ch) 47 | rs = r.db.Model(&models.Season{}).Where("id = ?", id).Select("*").Updates(&season) 48 | ch <- true 49 | }(done) 50 | 51 | if channels.OK(done) { 52 | if rs.Error != nil { 53 | return 0, rs.Error 54 | } 55 | 56 | return rs.RowsAffected, nil 57 | } 58 | return 0, rs.Error 59 | } 60 | 61 | // DeleteByID season by the id 62 | func (r *RepositorySeasonsCRUD) DeleteByID(id string) (int64, error) { 63 | var rs *gorm.DB 64 | done := make(chan bool) 65 | go func(ch chan<- bool) { 66 | defer close(ch) 67 | rs = r.db.Model(&models.Season{}).Where("id = ?", id).Delete(&models.Season{}) 68 | ch <- true 69 | }(done) 70 | 71 | if channels.OK(done) { 72 | if rs.Error != nil { 73 | return 0, rs.Error 74 | } 75 | return rs.RowsAffected, nil 76 | } 77 | return 0, rs.Error 78 | } 79 | 80 | // FindAll returns all the seasons from the DB 81 | func (r *RepositorySeasonsCRUD) FindAll(page int, size int) ([]models.Season, int, error) { 82 | var err error 83 | var num int64 84 | seasons := []models.Season{} 85 | done := make(chan bool) 86 | go func(ch chan<- bool) { 87 | defer close(ch) 88 | result := r.db.Model(&models.Season{}).Find(&seasons) 89 | result.Count(&num) 90 | err = result.Limit(size).Offset((page - 1) * size).Order("-ID").Scan(&seasons).Error 91 | if err != nil { 92 | ch <- false 93 | return 94 | } 95 | ch <- true 96 | }(done) 97 | if channels.OK(done) { 98 | return seasons, int(num), nil 99 | } 100 | return nil, 0, err 101 | } 102 | 103 | // FindByID return season from the DB 104 | func (r *RepositorySeasonsCRUD) FindByID(id string) (models.Season, error) { 105 | var err error 106 | season := models.Season{} 107 | done := make(chan bool) 108 | go func(ch chan<- bool) { 109 | defer close(ch) 110 | err = r.db.Model(&models.Season{}).Where("id = ?", id).Take(&season).Error 111 | if err != nil { 112 | ch <- false 113 | return 114 | } 115 | ch <- true 116 | }(done) 117 | if channels.OK(done) { 118 | return season, nil 119 | } 120 | 121 | if errors.Is(err, gorm.ErrRecordNotFound) { 122 | return models.Season{}, errors.New("season Not Found") 123 | } 124 | return models.Season{}, err 125 | } 126 | 127 | // Search season from the DB 128 | func (r *RepositorySeasonsCRUD) Search(q string, page int, size int) ([]models.Season, int, error) { 129 | var err error 130 | var num int64 131 | seasons := []models.Season{} 132 | done := make(chan bool) 133 | go func(ch chan<- bool) { 134 | defer close(ch) 135 | result := r.db.Model(&models.Season{}).Where("name LIKE ?", "%"+q+"%") 136 | result.Count(&num) 137 | err = result.Limit(size).Offset((page - 1) * size).Order("-updated_at").Scan(&seasons).Error 138 | if err != nil { 139 | ch <- false 140 | return 141 | } 142 | ch <- true 143 | }(done) 144 | if channels.OK(done) { 145 | return seasons, int(num), nil 146 | } 147 | if errors.Is(err, gorm.ErrRecordNotFound) { 148 | return []models.Season{}, 0, errors.New("seasons Not Found") 149 | } 150 | return []models.Season{}, 0, err 151 | } 152 | -------------------------------------------------------------------------------- /api/repository/crud/repositorySpokenLanguagesCrud.go: -------------------------------------------------------------------------------- 1 | package crud 2 | 3 | import ( 4 | "errors" 5 | 6 | "github.com/msterzhang/onelist/api/models" 7 | "github.com/msterzhang/onelist/api/utils/channels" 8 | 9 | "gorm.io/gorm" 10 | ) 11 | 12 | // RepositorySpokenLanguagesCRUD is the struct for the SpokenLanguage CRUD 13 | type RepositorySpokenLanguagesCRUD struct { 14 | db *gorm.DB 15 | } 16 | 17 | // NewRepositorySpokenLanguagesCRUD returns a new repository with DB connection 18 | func NewRepositorySpokenLanguagesCRUD(db *gorm.DB) *RepositorySpokenLanguagesCRUD { 19 | return &RepositorySpokenLanguagesCRUD{db} 20 | } 21 | 22 | // Save returns a new spokenlanguage created or an error 23 | func (r *RepositorySpokenLanguagesCRUD) Save(spokenlanguage models.SpokenLanguage) (models.SpokenLanguage, error) { 24 | var err error 25 | done := make(chan bool) 26 | go func(ch chan<- bool) { 27 | defer close(ch) 28 | err = r.db.Model(&models.SpokenLanguage{}).Create(&spokenlanguage).Error 29 | if err != nil { 30 | ch <- false 31 | return 32 | } 33 | ch <- true 34 | }(done) 35 | if channels.OK(done) { 36 | return spokenlanguage, nil 37 | } 38 | return models.SpokenLanguage{}, err 39 | } 40 | 41 | // UpdateByID update spokenlanguage from the DB 42 | func (r *RepositorySpokenLanguagesCRUD) UpdateByID(id string, spokenlanguage models.SpokenLanguage) (int64, error) { 43 | var rs *gorm.DB 44 | done := make(chan bool) 45 | go func(ch chan<- bool) { 46 | defer close(ch) 47 | rs = r.db.Model(&models.SpokenLanguage{}).Where("id = ?", id).Select("*").Updates(&spokenlanguage) 48 | ch <- true 49 | }(done) 50 | 51 | if channels.OK(done) { 52 | if rs.Error != nil { 53 | return 0, rs.Error 54 | } 55 | 56 | return rs.RowsAffected, nil 57 | } 58 | return 0, rs.Error 59 | } 60 | 61 | // DeleteByID spokenlanguage by the id 62 | func (r *RepositorySpokenLanguagesCRUD) DeleteByID(id string) (int64, error) { 63 | var rs *gorm.DB 64 | done := make(chan bool) 65 | go func(ch chan<- bool) { 66 | defer close(ch) 67 | rs = r.db.Model(&models.SpokenLanguage{}).Where("id = ?", id).Delete(&models.SpokenLanguage{}) 68 | ch <- true 69 | }(done) 70 | 71 | if channels.OK(done) { 72 | if rs.Error != nil { 73 | return 0, rs.Error 74 | } 75 | return rs.RowsAffected, nil 76 | } 77 | return 0, rs.Error 78 | } 79 | 80 | // FindAll returns all the spokenlanguages from the DB 81 | func (r *RepositorySpokenLanguagesCRUD) FindAll(page int, size int) ([]models.SpokenLanguage, int, error) { 82 | var err error 83 | var num int64 84 | spokenlanguages := []models.SpokenLanguage{} 85 | done := make(chan bool) 86 | go func(ch chan<- bool) { 87 | defer close(ch) 88 | result := r.db.Model(&models.SpokenLanguage{}).Find(&spokenlanguages) 89 | result.Count(&num) 90 | err = result.Limit(size).Offset((page - 1) * size).Order("-ID").Scan(&spokenlanguages).Error 91 | if err != nil { 92 | ch <- false 93 | return 94 | } 95 | ch <- true 96 | }(done) 97 | if channels.OK(done) { 98 | return spokenlanguages, int(num), nil 99 | } 100 | return nil, 0, err 101 | } 102 | 103 | // FindByID return spokenlanguage from the DB 104 | func (r *RepositorySpokenLanguagesCRUD) FindByID(id string) (models.SpokenLanguage, error) { 105 | var err error 106 | spokenlanguage := models.SpokenLanguage{} 107 | done := make(chan bool) 108 | go func(ch chan<- bool) { 109 | defer close(ch) 110 | err = r.db.Model(&models.SpokenLanguage{}).Where("id = ?", id).Take(&spokenlanguage).Error 111 | if err != nil { 112 | ch <- false 113 | return 114 | } 115 | ch <- true 116 | }(done) 117 | if channels.OK(done) { 118 | return spokenlanguage, nil 119 | } 120 | 121 | if errors.Is(err, gorm.ErrRecordNotFound) { 122 | return models.SpokenLanguage{}, errors.New("spokenlanguage Not Found") 123 | } 124 | return models.SpokenLanguage{}, err 125 | } 126 | 127 | // Search spokenlanguage from the DB 128 | func (r *RepositorySpokenLanguagesCRUD) Search(q string, page int, size int) ([]models.SpokenLanguage, int, error) { 129 | var err error 130 | var num int64 131 | spokenlanguages := []models.SpokenLanguage{} 132 | done := make(chan bool) 133 | go func(ch chan<- bool) { 134 | defer close(ch) 135 | result := r.db.Model(&models.SpokenLanguage{}).Where("name LIKE ?", "%"+q+"%") 136 | result.Count(&num) 137 | err = result.Limit(size).Offset((page - 1) * size).Order("-updated_at").Scan(&spokenlanguages).Error 138 | if err != nil { 139 | ch <- false 140 | return 141 | } 142 | ch <- true 143 | }(done) 144 | if channels.OK(done) { 145 | return spokenlanguages, int(num), nil 146 | } 147 | if errors.Is(err, gorm.ErrRecordNotFound) { 148 | return []models.SpokenLanguage{}, 0, errors.New("spokenlanguages Not Found") 149 | } 150 | return []models.SpokenLanguage{}, 0, err 151 | } 152 | -------------------------------------------------------------------------------- /api/repository/crud/repositoryTheCreditsCrud.go: -------------------------------------------------------------------------------- 1 | package crud 2 | 3 | import ( 4 | "errors" 5 | 6 | "github.com/msterzhang/onelist/api/models" 7 | "github.com/msterzhang/onelist/api/utils/channels" 8 | 9 | "gorm.io/gorm" 10 | ) 11 | 12 | // RepositoryTheCreditsCRUD is the struct for the TheCredit CRUD 13 | type RepositoryTheCreditsCRUD struct { 14 | db *gorm.DB 15 | } 16 | 17 | // NewRepositoryTheCreditsCRUD returns a new repository with DB connection 18 | func NewRepositoryTheCreditsCRUD(db *gorm.DB) *RepositoryTheCreditsCRUD { 19 | return &RepositoryTheCreditsCRUD{db} 20 | } 21 | 22 | // Save returns a new thecredit created or an error 23 | func (r *RepositoryTheCreditsCRUD) Save(thecredit models.TheCredit) (models.TheCredit, error) { 24 | var err error 25 | done := make(chan bool) 26 | go func(ch chan<- bool) { 27 | defer close(ch) 28 | err = r.db.Model(&models.TheCredit{}).Create(&thecredit).Error 29 | if err != nil { 30 | ch <- false 31 | return 32 | } 33 | ch <- true 34 | }(done) 35 | if channels.OK(done) { 36 | return thecredit, nil 37 | } 38 | return models.TheCredit{}, err 39 | } 40 | 41 | // UpdateByID update thecredit from the DB 42 | func (r *RepositoryTheCreditsCRUD) UpdateByID(id string, thecredit models.TheCredit) (int64, error) { 43 | var rs *gorm.DB 44 | done := make(chan bool) 45 | go func(ch chan<- bool) { 46 | defer close(ch) 47 | rs = r.db.Model(&models.TheCredit{}).Where("id = ?", id).Select("*").Updates(&thecredit) 48 | ch <- true 49 | }(done) 50 | 51 | if channels.OK(done) { 52 | if rs.Error != nil { 53 | return 0, rs.Error 54 | } 55 | 56 | return rs.RowsAffected, nil 57 | } 58 | return 0, rs.Error 59 | } 60 | 61 | // DeleteByID thecredit by the id 62 | func (r *RepositoryTheCreditsCRUD) DeleteByID(id string) (int64, error) { 63 | var rs *gorm.DB 64 | done := make(chan bool) 65 | go func(ch chan<- bool) { 66 | defer close(ch) 67 | rs = r.db.Model(&models.TheCredit{}).Where("id = ?", id).Delete(&models.TheCredit{}) 68 | ch <- true 69 | }(done) 70 | 71 | if channels.OK(done) { 72 | if rs.Error != nil { 73 | return 0, rs.Error 74 | } 75 | return rs.RowsAffected, nil 76 | } 77 | return 0, rs.Error 78 | } 79 | 80 | // FindAll returns all the thecredits from the DB 81 | func (r *RepositoryTheCreditsCRUD) FindAll(page int, size int) ([]models.TheCredit, int, error) { 82 | var err error 83 | var num int64 84 | thecredits := []models.TheCredit{} 85 | done := make(chan bool) 86 | go func(ch chan<- bool) { 87 | defer close(ch) 88 | result := r.db.Model(&models.TheCredit{}).Find(&thecredits) 89 | result.Count(&num) 90 | err = result.Limit(size).Offset((page - 1) * size).Order("-ID").Scan(&thecredits).Error 91 | if err != nil { 92 | ch <- false 93 | return 94 | } 95 | ch <- true 96 | }(done) 97 | if channels.OK(done) { 98 | return thecredits, int(num), nil 99 | } 100 | return nil, 0, err 101 | } 102 | 103 | // FindByID return thecredit from the DB 104 | func (r *RepositoryTheCreditsCRUD) FindByID(id string) (models.TheCredit, error) { 105 | var err error 106 | thecredit := models.TheCredit{} 107 | done := make(chan bool) 108 | go func(ch chan<- bool) { 109 | defer close(ch) 110 | err = r.db.Model(&models.TheCredit{}).Where("id = ?", id).Take(&thecredit).Error 111 | if err != nil { 112 | ch <- false 113 | return 114 | } 115 | ch <- true 116 | }(done) 117 | if channels.OK(done) { 118 | return thecredit, nil 119 | } 120 | 121 | if errors.Is(err, gorm.ErrRecordNotFound) { 122 | return models.TheCredit{}, errors.New("thecredit Not Found") 123 | } 124 | return models.TheCredit{}, err 125 | } 126 | 127 | // Search thecredit from the DB 128 | func (r *RepositoryTheCreditsCRUD) Search(q string, page int, size int) ([]models.TheCredit, int, error) { 129 | var err error 130 | var num int64 131 | thecredits := []models.TheCredit{} 132 | done := make(chan bool) 133 | go func(ch chan<- bool) { 134 | defer close(ch) 135 | result := r.db.Model(&models.TheCredit{}).Where("name LIKE ?", "%"+q+"%") 136 | result.Count(&num) 137 | err = result.Limit(size).Offset((page - 1) * size).Order("-updated_at").Scan(&thecredits).Error 138 | if err != nil { 139 | ch <- false 140 | return 141 | } 142 | ch <- true 143 | }(done) 144 | if channels.OK(done) { 145 | return thecredits, int(num), nil 146 | } 147 | if errors.Is(err, gorm.ErrRecordNotFound) { 148 | return []models.TheCredit{}, 0, errors.New("thecredits Not Found") 149 | } 150 | return []models.TheCredit{}, 0, err 151 | } 152 | -------------------------------------------------------------------------------- /api/repository/crud/repositoryThePersonsCrud.go: -------------------------------------------------------------------------------- 1 | package crud 2 | 3 | import ( 4 | "errors" 5 | 6 | "github.com/msterzhang/onelist/api/models" 7 | "github.com/msterzhang/onelist/api/utils/channels" 8 | 9 | "gorm.io/gorm" 10 | ) 11 | 12 | // RepositoryThePersonsCRUD is the struct for the ThePerson CRUD 13 | type RepositoryThePersonsCRUD struct { 14 | db *gorm.DB 15 | } 16 | 17 | // NewRepositoryThePersonsCRUD returns a new repository with DB connection 18 | func NewRepositoryThePersonsCRUD(db *gorm.DB) *RepositoryThePersonsCRUD { 19 | return &RepositoryThePersonsCRUD{db} 20 | } 21 | 22 | // Save returns a new theperson created or an error 23 | func (r *RepositoryThePersonsCRUD) Save(theperson models.ThePerson) (models.ThePerson, error) { 24 | var err error 25 | done := make(chan bool) 26 | go func(ch chan<- bool) { 27 | defer close(ch) 28 | err = r.db.Model(&models.ThePerson{}).Create(&theperson).Error 29 | if err != nil { 30 | ch <- false 31 | return 32 | } 33 | ch <- true 34 | }(done) 35 | if channels.OK(done) { 36 | return theperson, nil 37 | } 38 | return models.ThePerson{}, err 39 | } 40 | 41 | // UpdateByID update theperson from the DB 42 | func (r *RepositoryThePersonsCRUD) UpdateByID(id string, theperson models.ThePerson) (int64, error) { 43 | var rs *gorm.DB 44 | done := make(chan bool) 45 | go func(ch chan<- bool) { 46 | defer close(ch) 47 | rs = r.db.Model(&models.ThePerson{}).Where("id = ?", id).Select("*").Updates(&theperson) 48 | ch <- true 49 | }(done) 50 | 51 | if channels.OK(done) { 52 | if rs.Error != nil { 53 | return 0, rs.Error 54 | } 55 | 56 | return rs.RowsAffected, nil 57 | } 58 | return 0, rs.Error 59 | } 60 | 61 | // DeleteByID theperson by the id 62 | func (r *RepositoryThePersonsCRUD) DeleteByID(id string) (int64, error) { 63 | var rs *gorm.DB 64 | done := make(chan bool) 65 | go func(ch chan<- bool) { 66 | defer close(ch) 67 | rs = r.db.Model(&models.ThePerson{}).Where("id = ?", id).Delete(&models.ThePerson{}) 68 | ch <- true 69 | }(done) 70 | 71 | if channels.OK(done) { 72 | if rs.Error != nil { 73 | return 0, rs.Error 74 | } 75 | return rs.RowsAffected, nil 76 | } 77 | return 0, rs.Error 78 | } 79 | 80 | // FindAll returns all the thepersons from the DB 81 | func (r *RepositoryThePersonsCRUD) FindAll(page int, size int) ([]models.ThePerson, int, error) { 82 | var err error 83 | var num int64 84 | thepersons := []models.ThePerson{} 85 | done := make(chan bool) 86 | go func(ch chan<- bool) { 87 | defer close(ch) 88 | result := r.db.Model(&models.ThePerson{}).Find(&thepersons) 89 | result.Count(&num) 90 | err = result.Limit(size).Offset((page - 1) * size).Order("-ID").Scan(&thepersons).Error 91 | if err != nil { 92 | ch <- false 93 | return 94 | } 95 | ch <- true 96 | }(done) 97 | if channels.OK(done) { 98 | return thepersons, int(num), nil 99 | } 100 | return nil, 0, err 101 | } 102 | 103 | // FindByID return theperson from the DB 104 | func (r *RepositoryThePersonsCRUD) FindByID(id string) (models.ThePerson, error) { 105 | var err error 106 | theperson := models.ThePerson{} 107 | done := make(chan bool) 108 | go func(ch chan<- bool) { 109 | defer close(ch) 110 | err = r.db.Model(&models.ThePerson{}).Where("id = ?", id).Preload("TheMovies").Preload("TheTvs").Take(&theperson).Error 111 | if err != nil { 112 | ch <- false 113 | return 114 | } 115 | ch <- true 116 | }(done) 117 | if channels.OK(done) { 118 | return theperson, nil 119 | } 120 | 121 | if errors.Is(err, gorm.ErrRecordNotFound) { 122 | return models.ThePerson{}, errors.New("theperson Not Found") 123 | } 124 | return models.ThePerson{}, err 125 | } 126 | 127 | // Search theperson from the DB 128 | func (r *RepositoryThePersonsCRUD) Search(q string, page int, size int) ([]models.ThePerson, int, error) { 129 | var err error 130 | var num int64 131 | thepersons := []models.ThePerson{} 132 | done := make(chan bool) 133 | go func(ch chan<- bool) { 134 | defer close(ch) 135 | result := r.db.Model(&models.ThePerson{}).Where("name LIKE ?", "%"+q+"%") 136 | result.Count(&num) 137 | err = result.Limit(size).Offset((page - 1) * size).Order("-updated_at").Scan(&thepersons).Error 138 | if err != nil { 139 | ch <- false 140 | return 141 | } 142 | ch <- true 143 | }(done) 144 | if channels.OK(done) { 145 | return thepersons, int(num), nil 146 | } 147 | if errors.Is(err, gorm.ErrRecordNotFound) { 148 | return []models.ThePerson{}, 0, errors.New("thepersons Not Found") 149 | } 150 | return []models.ThePerson{}, 0, err 151 | } 152 | -------------------------------------------------------------------------------- /api/repository/crud/repositoryTheSeasonsCrud.go: -------------------------------------------------------------------------------- 1 | package crud 2 | 3 | import ( 4 | "errors" 5 | 6 | "github.com/msterzhang/onelist/api/models" 7 | "github.com/msterzhang/onelist/api/utils/channels" 8 | 9 | "gorm.io/gorm" 10 | ) 11 | 12 | // RepositoryTheSeasonsCRUD is the struct for the TheSeason CRUD 13 | type RepositoryTheSeasonsCRUD struct { 14 | db *gorm.DB 15 | } 16 | 17 | // NewRepositoryTheSeasonsCRUD returns a new repository with DB connection 18 | func NewRepositoryTheSeasonsCRUD(db *gorm.DB) *RepositoryTheSeasonsCRUD { 19 | return &RepositoryTheSeasonsCRUD{db} 20 | } 21 | 22 | // Save returns a new theseason created or an error 23 | func (r *RepositoryTheSeasonsCRUD) Save(theseason models.TheSeason) (models.TheSeason, error) { 24 | var err error 25 | done := make(chan bool) 26 | go func(ch chan<- bool) { 27 | defer close(ch) 28 | err = r.db.Model(&models.TheSeason{}).Create(&theseason).Error 29 | if err != nil { 30 | ch <- false 31 | return 32 | } 33 | ch <- true 34 | }(done) 35 | if channels.OK(done) { 36 | return theseason, nil 37 | } 38 | return models.TheSeason{}, err 39 | } 40 | 41 | // UpdateByID update theseason from the DB 42 | func (r *RepositoryTheSeasonsCRUD) UpdateByID(id string, theseason models.TheSeason) (int64, error) { 43 | var rs *gorm.DB 44 | done := make(chan bool) 45 | go func(ch chan<- bool) { 46 | defer close(ch) 47 | rs = r.db.Model(&models.TheSeason{}).Where("id = ?", id).Select("*").Updates(&theseason) 48 | ch <- true 49 | }(done) 50 | 51 | if channels.OK(done) { 52 | if rs.Error != nil { 53 | return 0, rs.Error 54 | } 55 | 56 | return rs.RowsAffected, nil 57 | } 58 | return 0, rs.Error 59 | } 60 | 61 | // DeleteByID theseason by the id 62 | func (r *RepositoryTheSeasonsCRUD) DeleteByID(id string) (int64, error) { 63 | var rs *gorm.DB 64 | done := make(chan bool) 65 | go func(ch chan<- bool) { 66 | defer close(ch) 67 | rs = r.db.Model(&models.TheSeason{}).Where("id = ?", id).Delete(&models.TheSeason{}) 68 | ch <- true 69 | }(done) 70 | 71 | if channels.OK(done) { 72 | if rs.Error != nil { 73 | return 0, rs.Error 74 | } 75 | return rs.RowsAffected, nil 76 | } 77 | return 0, rs.Error 78 | } 79 | 80 | // FindAll returns all the theseasons from the DB 81 | func (r *RepositoryTheSeasonsCRUD) FindAll(page int, size int) ([]models.TheSeason, int, error) { 82 | var err error 83 | var num int64 84 | theseasons := []models.TheSeason{} 85 | done := make(chan bool) 86 | go func(ch chan<- bool) { 87 | defer close(ch) 88 | result := r.db.Model(&models.TheSeason{}).Find(&theseasons) 89 | result.Count(&num) 90 | err = result.Limit(size).Offset((page - 1) * size).Order("-ID").Scan(&theseasons).Error 91 | if err != nil { 92 | ch <- false 93 | return 94 | } 95 | ch <- true 96 | }(done) 97 | if channels.OK(done) { 98 | return theseasons, int(num), nil 99 | } 100 | return nil, 0, err 101 | } 102 | 103 | // FindByID return theseason from the DB 104 | func (r *RepositoryTheSeasonsCRUD) FindByID(id string) (models.TheSeason, error) { 105 | var err error 106 | theseason := models.TheSeason{} 107 | done := make(chan bool) 108 | go func(ch chan<- bool) { 109 | defer close(ch) 110 | err = r.db.Model(&models.TheSeason{}).Where("id = ?", id).Preload("Episodes").Take(&theseason).Error 111 | if err != nil { 112 | ch <- false 113 | return 114 | } 115 | ch <- true 116 | }(done) 117 | if channels.OK(done) { 118 | return theseason, nil 119 | } 120 | 121 | if errors.Is(err, gorm.ErrRecordNotFound) { 122 | return models.TheSeason{}, errors.New("theseason Not Found") 123 | } 124 | return models.TheSeason{}, err 125 | } 126 | 127 | // Search theseason from the DB 128 | func (r *RepositoryTheSeasonsCRUD) Search(q string, page int, size int) ([]models.TheSeason, int, error) { 129 | var err error 130 | var num int64 131 | theseasons := []models.TheSeason{} 132 | done := make(chan bool) 133 | go func(ch chan<- bool) { 134 | defer close(ch) 135 | result := r.db.Model(&models.TheSeason{}).Where("name LIKE ?", "%"+q+"%") 136 | result.Count(&num) 137 | err = result.Limit(size).Offset((page - 1) * size).Order("-updated_at").Scan(&theseasons).Error 138 | if err != nil { 139 | ch <- false 140 | return 141 | } 142 | ch <- true 143 | }(done) 144 | if channels.OK(done) { 145 | return theseasons, int(num), nil 146 | } 147 | if errors.Is(err, gorm.ErrRecordNotFound) { 148 | return []models.TheSeason{}, 0, errors.New("theseasons Not Found") 149 | } 150 | return []models.TheSeason{}, 0, err 151 | } 152 | -------------------------------------------------------------------------------- /api/repository/crud/repositoryUsersCrud.go: -------------------------------------------------------------------------------- 1 | package crud 2 | 3 | import ( 4 | "errors" 5 | 6 | "github.com/msterzhang/onelist/api/models" 7 | "github.com/msterzhang/onelist/api/utils/channels" 8 | 9 | "gorm.io/gorm" 10 | ) 11 | 12 | // RepositoryUsersCRUD is the struct for the User CRUD 13 | type RepositoryUsersCRUD struct { 14 | db *gorm.DB 15 | } 16 | 17 | // NewRepositoryUsersCRUD returns a new repository with DB connection 18 | func NewRepositoryUsersCRUD(db *gorm.DB) *RepositoryUsersCRUD { 19 | return &RepositoryUsersCRUD{db} 20 | } 21 | 22 | // Save returns a new user created or an error 23 | func (r *RepositoryUsersCRUD) Save(user models.User) (models.User, error) { 24 | var err error 25 | done := make(chan bool) 26 | go func(ch chan<- bool) { 27 | defer close(ch) 28 | err = r.db.Model(&models.User{}).Create(&user).Error 29 | if err != nil { 30 | ch <- false 31 | return 32 | } 33 | ch <- true 34 | }(done) 35 | if channels.OK(done) { 36 | return user, nil 37 | } 38 | return models.User{}, err 39 | } 40 | 41 | // UpdateByID update user from the DB 42 | func (r *RepositoryUsersCRUD) UpdateByID(id string, user models.User) (int64, error) { 43 | var rs *gorm.DB 44 | done := make(chan bool) 45 | go func(ch chan<- bool) { 46 | defer close(ch) 47 | rs = r.db.Model(&models.User{}).Where("id = ?", id).Select("*").Updates(&user) 48 | ch <- true 49 | }(done) 50 | 51 | if channels.OK(done) { 52 | if rs.Error != nil { 53 | return 0, rs.Error 54 | } 55 | 56 | return rs.RowsAffected, nil 57 | } 58 | return 0, rs.Error 59 | } 60 | 61 | // DeleteByID user by the id 62 | func (r *RepositoryUsersCRUD) DeleteByID(id string) (int64, error) { 63 | var rs *gorm.DB 64 | done := make(chan bool) 65 | go func(ch chan<- bool) { 66 | defer close(ch) 67 | rs = r.db.Model(&models.User{}).Where("id = ?", id).Delete(&models.User{}) 68 | ch <- true 69 | }(done) 70 | 71 | if channels.OK(done) { 72 | if rs.Error != nil { 73 | return 0, rs.Error 74 | } 75 | return rs.RowsAffected, nil 76 | } 77 | return 0, rs.Error 78 | } 79 | 80 | // FindAll returns all the users from the DB 81 | func (r *RepositoryUsersCRUD) FindAll(page int, size int) ([]models.User, int, error) { 82 | var err error 83 | var num int64 84 | users := []models.User{} 85 | done := make(chan bool) 86 | go func(ch chan<- bool) { 87 | defer close(ch) 88 | result := r.db.Model(&models.User{}).Find(&users) 89 | result.Count(&num) 90 | err = result.Limit(size).Offset((page - 1) * size).Order("-ID").Scan(&users).Error 91 | if err != nil { 92 | ch <- false 93 | return 94 | } 95 | ch <- true 96 | }(done) 97 | if channels.OK(done) { 98 | return users, int(num), nil 99 | } 100 | return nil, 0, err 101 | } 102 | 103 | // FindByID return user from the DB 104 | func (r *RepositoryUsersCRUD) FindByID(id string) (models.User, error) { 105 | var err error 106 | user := models.User{} 107 | done := make(chan bool) 108 | go func(ch chan<- bool) { 109 | defer close(ch) 110 | err = r.db.Model(&models.User{}).Where("id = ?", id).Take(&user).Error 111 | if err != nil { 112 | ch <- false 113 | return 114 | } 115 | ch <- true 116 | }(done) 117 | if channels.OK(done) { 118 | return user, nil 119 | } 120 | 121 | if errors.Is(err, gorm.ErrRecordNotFound) { 122 | return models.User{}, errors.New("user Not Found") 123 | } 124 | return models.User{}, err 125 | } 126 | 127 | // Search user from the DB 128 | func (r *RepositoryUsersCRUD) Search(q string, page int, size int) ([]models.User, int, error) { 129 | var err error 130 | var num int64 131 | users := []models.User{} 132 | done := make(chan bool) 133 | go func(ch chan<- bool) { 134 | defer close(ch) 135 | result := r.db.Model(&models.User{}).Where("name LIKE ?", "%"+q+"%") 136 | result.Count(&num) 137 | err = result.Limit(size).Offset((page - 1) * size).Order("-updated_at").Scan(&users).Error 138 | if err != nil { 139 | ch <- false 140 | return 141 | } 142 | ch <- true 143 | }(done) 144 | if channels.OK(done) { 145 | return users, int(num), nil 146 | } 147 | if errors.Is(err, gorm.ErrRecordNotFound) { 148 | return []models.User{}, 0, errors.New("users Not Found") 149 | } 150 | return []models.User{}, 0, err 151 | } 152 | -------------------------------------------------------------------------------- /api/repository/repositoryBelongsToCollections.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import "github.com/msterzhang/onelist/api/models" 4 | 5 | type BelongsToCollectionRepository interface { 6 | Save(models.BelongsToCollection) (models.BelongsToCollection, error) 7 | FindAll(page int, size int) ([]models.BelongsToCollection, int, error) 8 | FindByID(string) (models.BelongsToCollection, error) 9 | UpdateByID(string, models.BelongsToCollection) (int64, error) 10 | DeleteByID(string) (int64, error) 11 | Search(string, int, int) ([]models.BelongsToCollection, int, error) 12 | } 13 | -------------------------------------------------------------------------------- /api/repository/repositoryCastItems.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import "github.com/msterzhang/onelist/api/models" 4 | 5 | type CastItemRepository interface { 6 | Save(models.CastItem) (models.CastItem, error) 7 | FindAll(page int, size int) ([]models.CastItem, int, error) 8 | FindByID(string) (models.CastItem, error) 9 | UpdateByID(string, models.CastItem) (int64, error) 10 | DeleteByID(string) (int64, error) 11 | Search(string, int, int) ([]models.CastItem, int, error) 12 | } 13 | -------------------------------------------------------------------------------- /api/repository/repositoryCrewItems.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import "github.com/msterzhang/onelist/api/models" 4 | 5 | type CrewItemRepository interface { 6 | Save(models.CrewItem) (models.CrewItem, error) 7 | FindAll(page int, size int) ([]models.CrewItem, int, error) 8 | FindByID(string) (models.CrewItem, error) 9 | UpdateByID(string, models.CrewItem) (int64, error) 10 | DeleteByID(string) (int64, error) 11 | Search(string, int, int) ([]models.CrewItem, int, error) 12 | } 13 | -------------------------------------------------------------------------------- /api/repository/repositoryEpisodes.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import "github.com/msterzhang/onelist/api/models" 4 | 5 | type EpisodeRepository interface { 6 | Save(models.Episode) (models.Episode, error) 7 | FindAll(page int, size int) ([]models.Episode, int, error) 8 | FindByID(string) (models.Episode, error) 9 | UpdateByID(string, models.Episode) (int64, error) 10 | DeleteByID(string) (int64, error) 11 | Search(string, int, int) ([]models.Episode, int, error) 12 | } 13 | -------------------------------------------------------------------------------- /api/repository/repositoryErrFiles.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import "github.com/msterzhang/onelist/api/models" 4 | 5 | type ErrFileRepository interface { 6 | Save(models.ErrFile) (models.ErrFile, error) 7 | FindAll(page int, size int) ([]models.ErrFile, int, error) 8 | FindByID(string) (models.ErrFile, error) 9 | UpdateByID(string, models.ErrFile) (int64, error) 10 | DeleteByID(string) (int64, error) 11 | Search(string, int, int) ([]models.ErrFile, int, error) 12 | GetErrFilesByWorkId(string, int, int) ([]models.ErrFile, int, error) 13 | } 14 | -------------------------------------------------------------------------------- /api/repository/repositoryGallerys.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import "github.com/msterzhang/onelist/api/models" 4 | 5 | type GalleryRepository interface { 6 | Save(models.Gallery) (models.Gallery, error) 7 | FindAll(page int, size int) ([]models.Gallery, int, error) 8 | FindAllByAdmin(page int, size int) ([]models.Gallery, int, error) 9 | FindByID(string) (models.Gallery, error) 10 | FindByUID(string) (models.Gallery, error) 11 | UpdateByID(string, models.Gallery) (int64, error) 12 | DeleteByID(string) (int64, error) 13 | Search(string, int, int) ([]models.Gallery, int, error) 14 | } 15 | -------------------------------------------------------------------------------- /api/repository/repositoryGenres.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import "github.com/msterzhang/onelist/api/models" 4 | 5 | type GenreRepository interface { 6 | Save(models.Genre) (models.Genre, error) 7 | FindAll(page int, size int) ([]models.Genre, int, error) 8 | FindByID(string) (models.Genre, error) 9 | UpdateByID(string, models.Genre) (int64, error) 10 | DeleteByID(string) (int64, error) 11 | Search(string, int, int) ([]models.Genre, int, error) 12 | FindByIdFilte(string, string, string, string, string, int, int) (models.Genre,int, error) 13 | } 14 | -------------------------------------------------------------------------------- /api/repository/repositoryHearts.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import "github.com/msterzhang/onelist/api/models" 4 | 5 | type HeartRepository interface { 6 | Save(models.Heart) (models.Heart, error) 7 | FindAll(page int, size int) ([]models.Heart, int, error) 8 | FindAllByUser(heart models.Heart, page int, size int) ([]models.Heart, int, error) 9 | FindByID(string) (models.Heart, error) 10 | ReNewHeartByHeart(models.Heart) (int64, error) 11 | UpdateByID(string, models.Heart) (int64, error) 12 | DeleteByID(string) (int64, error) 13 | Search(string, int, int) ([]models.Heart, int, error) 14 | } 15 | -------------------------------------------------------------------------------- /api/repository/repositoryLastEpisodeToAirs.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import "github.com/msterzhang/onelist/api/models" 4 | 5 | type LastEpisodeToAirRepository interface { 6 | Save(models.LastEpisodeToAir) (models.LastEpisodeToAir, error) 7 | FindAll(page int, size int) ([]models.LastEpisodeToAir, int, error) 8 | FindByID(string) (models.LastEpisodeToAir, error) 9 | UpdateByID(string, models.LastEpisodeToAir) (int64, error) 10 | DeleteByID(string) (int64, error) 11 | Search(string, int, int) ([]models.LastEpisodeToAir, int, error) 12 | } 13 | -------------------------------------------------------------------------------- /api/repository/repositoryNetworkss.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import "github.com/msterzhang/onelist/api/models" 4 | 5 | type NetworksRepository interface { 6 | Save(models.Networks) (models.Networks, error) 7 | FindAll(page int, size int) ([]models.Networks, int, error) 8 | FindByID(string) (models.Networks, error) 9 | UpdateByID(string, models.Networks) (int64, error) 10 | DeleteByID(string) (int64, error) 11 | Search(string, int, int) ([]models.Networks, int, error) 12 | } 13 | -------------------------------------------------------------------------------- /api/repository/repositoryNextEpisodeToAirs.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import "github.com/msterzhang/onelist/api/models" 4 | 5 | type NextEpisodeToAirRepository interface { 6 | Save(models.NextEpisodeToAir) (models.NextEpisodeToAir, error) 7 | FindAll(page int, size int) ([]models.NextEpisodeToAir, int, error) 8 | FindByID(string) (models.NextEpisodeToAir, error) 9 | UpdateByID(string, models.NextEpisodeToAir) (int64, error) 10 | DeleteByID(string) (int64, error) 11 | Search(string, int, int) ([]models.NextEpisodeToAir, int, error) 12 | } 13 | -------------------------------------------------------------------------------- /api/repository/repositoryPlayeds.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import "github.com/msterzhang/onelist/api/models" 4 | 5 | type PlayedRepository interface { 6 | Save(models.Played) (models.Played, error) 7 | ReNewByPlayed(models.Played) (int64, error) 8 | FindAll(page int, size int) ([]models.Played, int, error) 9 | FindAllByUser(played models.Played, page int, size int) ([]models.Played, int, error) 10 | FindByID(string) (models.Played, error) 11 | UpdateByID(string, models.Played) (int64, error) 12 | DeleteByID(string) (int64, error) 13 | Search(string, int, int) ([]models.Played, int, error) 14 | } 15 | -------------------------------------------------------------------------------- /api/repository/repositoryProductionCompanies.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import "github.com/msterzhang/onelist/api/models" 4 | 5 | type ProductionCompanieRepository interface { 6 | Save(models.ProductionCompanie) (models.ProductionCompanie, error) 7 | FindAll(page int, size int) ([]models.ProductionCompanie, int, error) 8 | FindByID(string) (models.ProductionCompanie, error) 9 | UpdateByID(string, models.ProductionCompanie) (int64, error) 10 | DeleteByID(string) (int64, error) 11 | Search(string, int, int) ([]models.ProductionCompanie, int, error) 12 | } 13 | -------------------------------------------------------------------------------- /api/repository/repositoryProductionCountries.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import "github.com/msterzhang/onelist/api/models" 4 | 5 | type ProductionCountrieRepository interface { 6 | Save(models.ProductionCountrie) (models.ProductionCountrie, error) 7 | FindAll(page int, size int) ([]models.ProductionCountrie, int, error) 8 | FindByID(string) (models.ProductionCountrie, error) 9 | UpdateByID(string, models.ProductionCountrie) (int64, error) 10 | DeleteByID(string) (int64, error) 11 | Search(string, int, int) ([]models.ProductionCountrie, int, error) 12 | } 13 | -------------------------------------------------------------------------------- /api/repository/repositorySeasons.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import "github.com/msterzhang/onelist/api/models" 4 | 5 | type SeasonRepository interface { 6 | Save(models.Season) (models.Season, error) 7 | FindAll(page int, size int) ([]models.Season, int, error) 8 | FindByID(string) (models.Season, error) 9 | UpdateByID(string, models.Season) (int64, error) 10 | DeleteByID(string) (int64, error) 11 | Search(string, int, int) ([]models.Season, int, error) 12 | } 13 | -------------------------------------------------------------------------------- /api/repository/repositorySpokenLanguages.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import "github.com/msterzhang/onelist/api/models" 4 | 5 | type SpokenLanguageRepository interface { 6 | Save(models.SpokenLanguage) (models.SpokenLanguage, error) 7 | FindAll(page int, size int) ([]models.SpokenLanguage, int, error) 8 | FindByID(string) (models.SpokenLanguage, error) 9 | UpdateByID(string, models.SpokenLanguage) (int64, error) 10 | DeleteByID(string) (int64, error) 11 | Search(string, int, int) ([]models.SpokenLanguage, int, error) 12 | } 13 | -------------------------------------------------------------------------------- /api/repository/repositoryStars.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import "github.com/msterzhang/onelist/api/models" 4 | 5 | type StarRepository interface { 6 | Save(models.Star) (models.Star, error) 7 | FindAll(page int, size int) ([]models.Star, int, error) 8 | FindAllByUser(star models.Star, page int, size int) ([]models.Star, int, error) 9 | FindByID(string) (models.Star, error) 10 | UpdateByID(string, models.Star) (int64, error) 11 | ReNewStarByStar(models.Star) (int64, error) 12 | DeleteByID(string) (int64, error) 13 | Search(string, int, int) ([]models.Star, int, error) 14 | } 15 | -------------------------------------------------------------------------------- /api/repository/repositoryTheCredits.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import "github.com/msterzhang/onelist/api/models" 4 | 5 | type TheCreditRepository interface { 6 | Save(models.TheCredit) (models.TheCredit, error) 7 | FindAll(page int, size int) ([]models.TheCredit, int, error) 8 | FindByID(string) (models.TheCredit, error) 9 | UpdateByID(string, models.TheCredit) (int64, error) 10 | DeleteByID(string) (int64, error) 11 | Search(string, int, int) ([]models.TheCredit, int, error) 12 | } 13 | -------------------------------------------------------------------------------- /api/repository/repositoryTheMovies.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import "github.com/msterzhang/onelist/api/models" 4 | 5 | type TheMovieRepository interface { 6 | Save(models.TheMovie) (models.TheMovie, error) 7 | FindAll(page int, size int) ([]models.TheMovie, int, error) 8 | FindByID(string) (models.TheMovie, error) 9 | UpdateByID(string, models.TheMovie) (int64, error) 10 | DeleteByID(string) (int64, error) 11 | Search(string, int, int) ([]models.TheMovie, int, error) 12 | Sort(string,string,string, int, int) ([]models.TheMovie, int, error) 13 | FindByGalleryId(string, int, int) ([]models.TheMovie, int, error) 14 | } 15 | -------------------------------------------------------------------------------- /api/repository/repositoryThePersons.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import "github.com/msterzhang/onelist/api/models" 4 | 5 | type ThePersonRepository interface { 6 | Save(models.ThePerson) (models.ThePerson, error) 7 | FindAll(page int, size int) ([]models.ThePerson, int, error) 8 | FindByID(string) (models.ThePerson, error) 9 | UpdateByID(string, models.ThePerson) (int64, error) 10 | DeleteByID(string) (int64, error) 11 | Search(string, int, int) ([]models.ThePerson, int, error) 12 | } 13 | -------------------------------------------------------------------------------- /api/repository/repositoryTheSeasons.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import "github.com/msterzhang/onelist/api/models" 4 | 5 | type TheSeasonRepository interface { 6 | Save(models.TheSeason) (models.TheSeason, error) 7 | FindAll(page int, size int) ([]models.TheSeason, int, error) 8 | FindByID(string) (models.TheSeason, error) 9 | UpdateByID(string, models.TheSeason) (int64, error) 10 | DeleteByID(string) (int64, error) 11 | Search(string, int, int) ([]models.TheSeason, int, error) 12 | } 13 | -------------------------------------------------------------------------------- /api/repository/repositoryTheTvs.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import "github.com/msterzhang/onelist/api/models" 4 | 5 | type TheTvRepository interface { 6 | Save(models.TheTv) (models.TheTv, error) 7 | FindAll(page int, size int) ([]models.TheTv, int, error) 8 | FindByID(string) (models.TheTv, error) 9 | UpdateByID(string, models.TheTv) (int64, error) 10 | DeleteByID(string) (int64, error) 11 | Search(string, int, int) ([]models.TheTv, int, error) 12 | Sort(string,string,string, int, int) ([]models.TheTv, int, error) 13 | FindByGalleryId(string, int, int) ([]models.TheTv, int, error) 14 | } 15 | -------------------------------------------------------------------------------- /api/repository/repositoryUsers.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import "github.com/msterzhang/onelist/api/models" 4 | 5 | type UserRepository interface { 6 | Save(models.User) (models.User, error) 7 | FindAll(page int, size int) ([]models.User, int, error) 8 | FindByID(string) (models.User, error) 9 | UpdateByID(string, models.User) (int64, error) 10 | DeleteByID(string) (int64, error) 11 | Search(string, int, int) ([]models.User, int, error) 12 | } 13 | -------------------------------------------------------------------------------- /api/repository/repositoryWorks.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import "github.com/msterzhang/onelist/api/models" 4 | 5 | type WorkRepository interface { 6 | Save(models.Work) (models.Work, error) 7 | FindAll(page int, size int) ([]models.Work, int, error) 8 | FindByID(string) (models.Work, error) 9 | UpdateByID(string, models.Work) (int64, error) 10 | DeleteByID(string) (int64, error) 11 | Search(string, int, int) ([]models.Work, int, error) 12 | GetWorkListByGalleryId(string, int, int) ([]models.Work, int, error) 13 | } 14 | -------------------------------------------------------------------------------- /api/security/password.go: -------------------------------------------------------------------------------- 1 | package security 2 | 3 | import ( 4 | "encoding/base64" 5 | "errors" 6 | ) 7 | 8 | // Hash make a password hash 9 | func Hash(password string) (string, error) { 10 | encoded := base64.StdEncoding.EncodeToString([]byte(password)) 11 | return encoded, nil 12 | } 13 | 14 | // DecodePassword Decode the hashed password 15 | func DecodePassword(hashedPassword string) (string, error) { 16 | e, err := base64.StdEncoding.DecodeString(hashedPassword) 17 | if err != nil { 18 | return "", err 19 | } 20 | return string(e), nil 21 | } 22 | 23 | // VerifyPassword verify the hashed password 24 | func VerifyPassword(hashedPassword, password string) error { 25 | e, err := base64.StdEncoding.DecodeString(hashedPassword) 26 | if err != nil { 27 | return err 28 | } 29 | if string(e) != password { 30 | return errors.New("密码错误") 31 | } 32 | return nil 33 | } 34 | -------------------------------------------------------------------------------- /api/service/service.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "errors" 5 | 6 | "github.com/msterzhang/onelist/api/database" 7 | "github.com/msterzhang/onelist/api/models" 8 | 9 | "gorm.io/gorm" 10 | ) 11 | 12 | // 处理电视用户是否已点赞,收藏及点了最爱 13 | func TheTvService(theTv models.TheTv, userId string) models.TheTv { 14 | star := models.Star{} 15 | played := models.Played{} 16 | heart := models.Heart{} 17 | db := database.NewDb() 18 | err := db.Model(&models.Star{}).Where("user_id = ? AND data_id = ? AND data_type = ?", userId, theTv.ID, "tv").First(&star).Error 19 | if !errors.Is(err, gorm.ErrRecordNotFound) && star.Id != 0 { 20 | theTv.Star = true 21 | } 22 | err = db.Model(&models.Played{}).Where("user_id = ? AND data_id = ? AND data_type = ?", userId, theTv.ID, "tv").First(&played).Error 23 | if !errors.Is(err, gorm.ErrRecordNotFound) && played.Id != 0 { 24 | theTv.Played = true 25 | } 26 | err = db.Model(&models.Heart{}).Where("user_id = ? AND data_id = ? AND data_type = ?", userId, theTv.ID, "tv").First(&heart).Error 27 | if !errors.Is(err, gorm.ErrRecordNotFound) && heart.Id != 0 { 28 | theTv.Heart = true 29 | } 30 | return theTv 31 | } 32 | 33 | // 处理电视用户是否已点赞,收藏及点了最爱 34 | func TheTvsService(theTvs []models.TheTv, userId string) []models.TheTv { 35 | var newTheTvs []models.TheTv 36 | for _, theTv := range theTvs { 37 | newTheTvs = append(newTheTvs, TheTvService(theTv, userId)) 38 | } 39 | return newTheTvs 40 | } 41 | 42 | // 处理电影用户是否已点赞,收藏及点了最爱 43 | func TheMovieService(theMovie models.TheMovie, userId string) models.TheMovie { 44 | star := models.Star{} 45 | played := models.Played{} 46 | heart := models.Heart{} 47 | db := database.NewDb() 48 | err := db.Model(&models.Star{}).Where("user_id = ? AND data_id = ? AND data_type = ?", userId, theMovie.ID, "movie").First(&star).Error 49 | if !errors.Is(err, gorm.ErrRecordNotFound) && star.Id != 0 { 50 | theMovie.Star = true 51 | } 52 | err = db.Model(&models.Played{}).Where("user_id = ? AND data_id = ? AND data_type = ?", userId, theMovie.ID, "movie").First(&played).Error 53 | if !errors.Is(err, gorm.ErrRecordNotFound) && played.Id != 0 { 54 | theMovie.Played = true 55 | } 56 | err = db.Model(&models.Heart{}).Where("user_id = ? AND data_id = ? AND data_type = ?", userId, theMovie.ID, "movie").First(&heart).Error 57 | if !errors.Is(err, gorm.ErrRecordNotFound) && heart.Id != 0 { 58 | theMovie.Heart = true 59 | } 60 | return theMovie 61 | } 62 | 63 | // 处理电影用户是否已点赞,收藏及点了最爱 64 | func TheMoviesService(theMovies []models.TheMovie, userId string) []models.TheMovie { 65 | var newTheMovies []models.TheMovie 66 | for _, theMovie := range theMovies { 67 | newTheMovies = append(newTheMovies, TheMovieService(theMovie, userId)) 68 | } 69 | return newTheMovies 70 | } 71 | -------------------------------------------------------------------------------- /api/utils/cache/cache.go: -------------------------------------------------------------------------------- 1 | package cache 2 | 3 | import ( 4 | "github.com/patrickmn/go-cache" 5 | "log" 6 | "time" 7 | ) 8 | 9 | var cDb *cache.Cache 10 | 11 | func InitCache() { 12 | cDb = cache.New(10*time.Minute, 60*time.Minute) 13 | log.Println("初始化缓存系统成功!") 14 | } 15 | 16 | func NewCache() *cache.Cache { 17 | return cDb 18 | } 19 | -------------------------------------------------------------------------------- /api/utils/channels/channels.go: -------------------------------------------------------------------------------- 1 | package channels 2 | 3 | // OK returns if a operation was successful 4 | func OK(done chan bool) bool { 5 | select { 6 | case ok := <-done: 7 | if ok { 8 | return ok 9 | } 10 | 11 | } 12 | return false 13 | } 14 | -------------------------------------------------------------------------------- /api/utils/dir/dir.go: -------------------------------------------------------------------------------- 1 | package dir 2 | 3 | import "os" 4 | 5 | // 递归遍历目录中的文件 6 | func GetFilesPath(path string, fileList []string) []string { 7 | fs, err := os.ReadDir(path) 8 | if err != nil { 9 | return fileList 10 | } 11 | for _, file := range fs { 12 | // 防止拼接path错误 13 | if path[len(path)-1:] != "/" { 14 | path += "/" 15 | } 16 | if file.IsDir() { 17 | fileList = GetFilesPath(path+file.Name()+"/", fileList) 18 | } else { 19 | fileList = append(fileList, path+file.Name()) 20 | } 21 | } 22 | return fileList 23 | } 24 | 25 | // 获取目录中的所有文件 26 | func GetFilesByPath(path string) []string { 27 | fileList := []string{} 28 | return GetFilesPath(path, fileList) 29 | } 30 | 31 | func DirExists(path string) bool { 32 | _, err := os.Stat(path) 33 | if err != nil { 34 | return os.IsExist(err) 35 | } 36 | return true 37 | } 38 | 39 | func FileExists(path string) bool { 40 | _, err := os.Stat(path) 41 | if err != nil { 42 | return os.IsExist(err) 43 | } 44 | return true 45 | } 46 | -------------------------------------------------------------------------------- /api/utils/extract/extract.go: -------------------------------------------------------------------------------- 1 | package extract 2 | 3 | import ( 4 | "errors" 5 | "path/filepath" 6 | "regexp" 7 | "strconv" 8 | ) 9 | 10 | func removeEndingOne(s string) string { 11 | if len(s) > 0 && s[len(s)-1] == '1' { 12 | return s[:len(s)-1] 13 | } 14 | return s 15 | } 16 | 17 | // 过滤电影文件名 18 | func ExtractMovieName(s string) string { 19 | oldName := s 20 | // 删除发布年份和文件扩展名 21 | re := regexp.MustCompile(`\d{4}`) 22 | s = re.ReplaceAllString(s, "") 23 | // 兼容全是纯数字的 24 | if len(s) == 0 { 25 | re = regexp.MustCompile(`\d+`) 26 | matchenNumbers := re.FindAllString(oldName, -1) 27 | if len(matchenNumbers) > 0 { 28 | s = matchenNumbers[0] 29 | } 30 | } 31 | // 删除括号及其内容 32 | re = regexp.MustCompile(`\s*\([^)]+\)`) 33 | s = re.ReplaceAllString(s, "") 34 | 35 | // 提取中文名称 36 | re = regexp.MustCompile(`[\p{Han}\d{1,2}]+`) 37 | matches := re.FindAllString(s, -1) 38 | if len(matches) > 0 { 39 | name := removeEndingOne(matches[0]) 40 | return name 41 | } 42 | return s 43 | } 44 | 45 | // 根据文件名获取剧集季及集信息 46 | func ExtractNumberWithFile(file string) (int, int, error) { 47 | p, err := filepath.Abs(file) 48 | if err != nil { 49 | return 0, 0, err 50 | } 51 | SeasonNumber := 0 52 | EpisodeNumber := 0 53 | fileName := filepath.Base(p) 54 | re := regexp.MustCompile(`[Ss](\d{1,2})[Ee](\d{1,4})`) 55 | match := re.FindStringSubmatch(fileName) 56 | if len(match) < 3 { 57 | return 0, 0, errors.New("get number error") 58 | } 59 | season := match[1] 60 | episode := match[2] 61 | SeasonNumber, err = strconv.Atoi(season) 62 | if err != nil { 63 | return 0, 0, err 64 | } 65 | EpisodeNumber, err = strconv.Atoi(episode) 66 | if err != nil { 67 | return 0, 0, err 68 | } 69 | return SeasonNumber, EpisodeNumber, nil 70 | } 71 | -------------------------------------------------------------------------------- /api/utils/gpool/gpool.go: -------------------------------------------------------------------------------- 1 | package gpool 2 | 3 | import ( 4 | "sync" 5 | ) 6 | 7 | type Pool struct { 8 | queue chan int 9 | wg *sync.WaitGroup 10 | } 11 | 12 | func New(size int) *Pool { 13 | if size <= 0 { 14 | size = 1 15 | } 16 | return &Pool{ 17 | queue: make(chan int, size), 18 | wg: &sync.WaitGroup{}, 19 | } 20 | } 21 | 22 | func (p *Pool) Add(delta int) { 23 | for i := 0; i < delta; i++ { 24 | p.queue <- 1 25 | } 26 | for i := 0; i > delta; i-- { 27 | <-p.queue 28 | } 29 | p.wg.Add(delta) 30 | } 31 | 32 | func (p *Pool) Done() { 33 | <-p.queue 34 | p.wg.Done() 35 | } 36 | 37 | func (p *Pool) Wait() { 38 | p.wg.Wait() 39 | } 40 | -------------------------------------------------------------------------------- /api/utils/tools/tools.go: -------------------------------------------------------------------------------- 1 | package tools 2 | 3 | import ( 4 | "math/rand" 5 | "time" 6 | ) 7 | 8 | var letterRunes = []rune("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") 9 | 10 | func RandStringRunes(n int) string { 11 | var rand = rand.New(rand.NewSource(time.Now().UnixNano())) 12 | b := make([]rune, n) 13 | for i := range b { 14 | b[i] = letterRunes[rand.Intn(len(letterRunes))] 15 | } 16 | return string(b) 17 | } 18 | -------------------------------------------------------------------------------- /auto/load.go: -------------------------------------------------------------------------------- 1 | package auto 2 | 3 | import ( 4 | "database/sql" 5 | "errors" 6 | "log" 7 | 8 | "github.com/msterzhang/onelist/api/database" 9 | "github.com/msterzhang/onelist/api/models" 10 | "github.com/msterzhang/onelist/api/utils/cache" 11 | "github.com/msterzhang/onelist/config" 12 | "gorm.io/gorm" 13 | ) 14 | 15 | func Load() { 16 | if config.DBDRIVER == "mysql" { 17 | db, err := sql.Open(config.DBDRIVER, config.DBDATAURL) 18 | if err != nil { 19 | log.Fatal(err) 20 | } 21 | defer db.Close() 22 | _, err = db.Exec("CREATE DATABASE " + config.DbName + " default character set utf8mb4 collate utf8mb4_general_ci") 23 | if err != nil { 24 | log.Println("数据库已存在!") 25 | InitDatabase() 26 | return 27 | } 28 | log.Println("数据库创建成功!", err) 29 | } else { 30 | InitDatabase() 31 | } 32 | } 33 | 34 | // 初始化数据库 35 | func InitDatabase() { 36 | err := database.InitDb() 37 | if err != nil { 38 | log.Fatal("Gorm初始化数据库失败!报错:" + err.Error()) 39 | } 40 | AutoLoad() 41 | InitAmdin() 42 | cache.InitCache() 43 | } 44 | 45 | // 初始化管理员 46 | func InitAmdin() { 47 | db := database.NewDb() 48 | user := models.User{} 49 | err := db.Model(&models.User{}).Where("user_email = ?", config.UserEmail).First(&user).Error 50 | if errors.Is(err, gorm.ErrRecordNotFound) { 51 | user.UserEmail = config.UserEmail 52 | user.UserPassword = config.UserPassword 53 | user.IsAdmin = true 54 | err := db.Model(&models.User{}).Create(&user).Error 55 | if err != nil { 56 | log.Fatal(err) 57 | return 58 | } 59 | return 60 | } 61 | if err != nil { 62 | log.Fatal(err) 63 | } 64 | } 65 | 66 | // 初始化表信息 67 | func AutoLoad() { 68 | var err error 69 | db := database.NewDb() 70 | err = db.AutoMigrate(&models.TheTv{}) 71 | if err != nil { 72 | log.Fatal(err) 73 | } 74 | 75 | err = db.AutoMigrate(&models.Season{}) 76 | if err != nil { 77 | log.Fatal(err) 78 | } 79 | 80 | err = db.AutoMigrate(&models.LastEpisodeToAir{}) 81 | if err != nil { 82 | log.Fatal(err) 83 | } 84 | 85 | err = db.AutoMigrate(&models.NextEpisodeToAir{}) 86 | if err != nil { 87 | log.Fatal(err) 88 | } 89 | 90 | err = db.AutoMigrate(&models.Networks{}) 91 | if err != nil { 92 | log.Fatal(err) 93 | } 94 | 95 | err = db.AutoMigrate(&models.Genre{}) 96 | if err != nil { 97 | log.Fatal(err) 98 | } 99 | 100 | err = db.AutoMigrate(&models.ProductionCompanie{}) 101 | if err != nil { 102 | log.Fatal(err) 103 | } 104 | 105 | err = db.AutoMigrate(&models.ProductionCountrie{}) 106 | if err != nil { 107 | log.Fatal(err) 108 | } 109 | 110 | err = db.AutoMigrate(&models.SpokenLanguage{}) 111 | if err != nil { 112 | log.Fatal(err) 113 | } 114 | 115 | err = db.AutoMigrate(&models.BelongsToCollection{}) 116 | if err != nil { 117 | log.Fatal(err) 118 | } 119 | 120 | err = db.AutoMigrate(&models.TheMovie{}) 121 | if err != nil { 122 | log.Fatal(err) 123 | } 124 | 125 | err = db.AutoMigrate(&models.TheCredit{}) 126 | if err != nil { 127 | log.Fatal(err) 128 | } 129 | 130 | err = db.AutoMigrate(&models.CastItem{}) 131 | if err != nil { 132 | log.Fatal(err) 133 | } 134 | 135 | err = db.AutoMigrate(&models.CrewItem{}) 136 | if err != nil { 137 | log.Fatal(err) 138 | } 139 | 140 | err = db.AutoMigrate(&models.Episode{}) 141 | if err != nil { 142 | log.Fatal(err) 143 | } 144 | 145 | err = db.AutoMigrate(&models.TheSeason{}) 146 | if err != nil { 147 | log.Fatal(err) 148 | } 149 | 150 | err = db.AutoMigrate(&models.ThePerson{}) 151 | if err != nil { 152 | log.Fatal(err) 153 | } 154 | 155 | err = db.AutoMigrate(&models.Work{}) 156 | if err != nil { 157 | log.Fatal(err) 158 | } 159 | 160 | err = db.AutoMigrate(&models.Gallery{}) 161 | if err != nil { 162 | log.Fatal(err) 163 | } 164 | err = db.AutoMigrate(&models.ErrFile{}) 165 | if err != nil { 166 | log.Fatal(err) 167 | } 168 | 169 | err = db.AutoMigrate(&models.User{}) 170 | if err != nil { 171 | log.Fatal(err) 172 | } 173 | 174 | err = db.AutoMigrate(&models.Star{}) 175 | if err != nil { 176 | log.Fatal(err) 177 | } 178 | 179 | err = db.AutoMigrate(&models.Heart{}) 180 | if err != nil { 181 | log.Fatal(err) 182 | } 183 | 184 | err = db.AutoMigrate(&models.Played{}) 185 | if err != nil { 186 | log.Fatal(err) 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | appName="onelist" 2 | builtAt="$(date +'%F %T %z')" 3 | goVersion=$(go version | sed 's/go version //') 4 | gitAuthor="msterzhang " 5 | gitCommit=$(git log --pretty=format:"%h" -1) 6 | 7 | if [ "$1" = "dev" ]; then 8 | version="dev" 9 | webVersion="dev" 10 | else 11 | version=$(git describe --abbrev=0 --tags) 12 | webVersion=$(wget -qO- -t1 -T2 "https://api.github.com/repos/msterzhang/onelist-web/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g') 13 | fi 14 | 15 | echo "backend version: $version" 16 | echo "frontend version: $webVersion" 17 | 18 | ldflags="-w -s" 19 | 20 | FetchWebDev() { 21 | curl -L https://codeload.github.com/msterzhang/onelist-web/tar.gz/refs/heads/dev -o web-dist-dev.tar.gz 22 | tar -zxvf web-dist-dev.tar.gz 23 | rm -rf public/dist 24 | mv -f web-dist-dev/dist public 25 | rm -rf web-dist-dev web-dist-dev.tar.gz 26 | } 27 | 28 | FetchWebRelease() { 29 | curl -L https://github.com/msterzhang/onelist-web/releases/latest/download/dist.tar.gz -o dist.tar.gz 30 | tar -zxvf dist.tar.gz 31 | rm -rf public/dist 32 | mv -f dist public 33 | rm -rf dist.tar.gz 34 | } 35 | 36 | BuildWinArm64() { 37 | echo building for windows-arm64 38 | chmod +x ./wrapper/zcc-arm64 39 | chmod +x ./wrapper/zcxx-arm64 40 | export GOOS=windows 41 | export GOARCH=arm64 42 | export CC=$(pwd)/wrapper/zcc-arm64 43 | export CXX=$(pwd)/wrapper/zcxx-arm64 44 | go build -o "$1" -ldflags="$ldflags" -tags=jsoniter . 45 | } 46 | 47 | BuildDev() { 48 | rm -rf .git/ 49 | xgo -targets=linux/amd64,windows/amd64,darwin/amd64 -out "$appName" -ldflags="$ldflags" -tags=jsoniter . 50 | mkdir -p "dist" 51 | mv onelist-* dist 52 | cd dist 53 | upx -9 ./onelist-linux* 54 | upx -9 ./onelist-windows-amd64.exe 55 | find . -type f -print0 | xargs -0 md5sum >md5.txt 56 | cat md5.txt 57 | } 58 | 59 | BuildDocker() { 60 | go build -o ./bin/onelist -ldflags="$ldflags" -tags=jsoniter . 61 | } 62 | 63 | BuildRelease() { 64 | rm -rf .git/ 65 | mkdir -p "build" 66 | muslflags="--extldflags '-static -fpic' $ldflags" 67 | BASE="https://onelist.top/" 68 | FILES=(x86_64-linux-musl-cross aarch64-linux-musl-cross arm-linux-musleabihf-cross mips-linux-musl-cross mips64-linux-musl-cross mips64el-linux-musl-cross mipsel-linux-musl-cross powerpc64le-linux-musl-cross s390x-linux-musl-cross) 69 | for i in "${FILES[@]}"; do 70 | url="${BASE}${i}.tgz" 71 | curl -L -o "${i}.tgz" "${url}" 72 | sudo tar xf "${i}.tgz" --strip-components 1 -C /usr/local 73 | done 74 | OS_ARCHES=(linux-musl-amd64 linux-musl-arm64 linux-musl-arm linux-musl-mips linux-musl-mips64 linux-musl-mips64le linux-musl-mipsle linux-musl-ppc64le linux-musl-s390x) 75 | CGO_ARGS=(x86_64-linux-musl-gcc aarch64-linux-musl-gcc arm-linux-musleabihf-gcc mips-linux-musl-gcc mips64-linux-musl-gcc mips64el-linux-musl-gcc mipsel-linux-musl-gcc powerpc64le-linux-musl-gcc s390x-linux-musl-gcc) 76 | for i in "${!OS_ARCHES[@]}"; do 77 | os_arch=${OS_ARCHES[$i]} 78 | cgo_cc=${CGO_ARGS[$i]} 79 | echo building for ${os_arch} 80 | export GOOS=${os_arch%%-*} 81 | export GOARCH=${os_arch##*-} 82 | export CC=${cgo_cc} 83 | export CGO_ENABLED=1 84 | go build -o ./build/$appName-$os_arch -ldflags="$muslflags" -tags=jsoniter . 85 | done 86 | BuildWinArm64 ./build/onelist-windows-arm64.exe 87 | xgo -out "$appName" -ldflags="$ldflags" -tags=jsoniter . 88 | upx -9 ./onelist-linux-amd64 89 | upx -9 ./onelist-windows-amd64.exe 90 | mv onelist-* build 91 | } 92 | 93 | MakeRelease() { 94 | cd build 95 | mkdir compress 96 | for i in $(find . -type f -name "$appName-linux-*"); do 97 | cp "$i" onelist 98 | tar -czvf compress/"$i".tar.gz onelist 99 | rm -f onelist 100 | done 101 | for i in $(find . -type f -name "$appName-darwin-*"); do 102 | cp "$i" onelist 103 | tar -czvf compress/"$i".tar.gz onelist 104 | rm -f onelist 105 | done 106 | for i in $(find . -type f -name "$appName-windows-*"); do 107 | cp "$i" onelist.exe 108 | zip compress/$(echo $i | sed 's/\.[^.]*$//').zip onelist.exe 109 | rm -f onelist.exe 110 | done 111 | cd compress 112 | find . -type f -print0 | xargs -0 md5sum >md5.txt 113 | cat md5.txt 114 | cd ../.. 115 | } 116 | 117 | if [ "$1" = "dev" ]; then 118 | FetchWebDev 119 | if [ "$2" = "docker" ]; then 120 | BuildDocker 121 | else 122 | BuildDev 123 | fi 124 | elif [ "$1" = "release" ]; then 125 | FetchWebRelease 126 | if [ "$2" = "docker" ]; then 127 | BuildDocker 128 | else 129 | BuildRelease 130 | MakeRelease 131 | fi 132 | else 133 | echo -e "Parameter error" 134 | fi -------------------------------------------------------------------------------- /config.env: -------------------------------------------------------------------------------- 1 | 2 | # 服务设置 3 | # 注意要改为未被占用的端口 4 | API_PORT=5245 5 | FaviconicoUrl=http://wework.qpic.cn/wwpic/818353_fizV30xbQCGPQRP_1677394564/0 6 | API_SECRET=gnBEKCN0wbEkffBL8zpoKHmRcHxZ6Eah 7 | 8 | # 网站名称 9 | Title=OneList 10 | # Env有两种模式,Debug及Release,主要用在数据库为mysql时候,需要注意修改Env环境和mysql密码对应 11 | Env=Debug 12 | 13 | # 管理员账户设置,用于初始化管理员账户 14 | UserEmail=xxxx.@qq.com 15 | UserPassword=xxxxx 16 | 17 | # 数据库设置 18 | DB_DRIVER=sqlite 19 | DB_USER=root 20 | DbName=onelist 21 | 22 | # 如果上面DB_DRIVER类型为mysql,就需要正确填下以下参数 23 | DB_PASSWORD_Debug=123456 24 | DB_PASSWORD_Release=123456 25 | 26 | # 下载刮削图片到本地 27 | DownLoadImage=是 28 | # 留空则表示使用本地缓存图片,否则使用https://image.tmdb.org 29 | ImgUrl=https://image.tmdb.org 30 | # 允许刮削alist中的视频文件类型 31 | VideoTypes=.mp4,.mkv,.flv 32 | 33 | # TheMovieDb Key 34 | # 在https://www.themoviedb.org网站申请 35 | KeyDb=22f10ca52f109158ac7fe064ebbcf697 36 | -------------------------------------------------------------------------------- /config/config.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strconv" 7 | "strings" 8 | 9 | "github.com/joho/godotenv" 10 | "github.com/msterzhang/onelist/api/models" 11 | ) 12 | 13 | var ( 14 | EnvFile = "config.env" 15 | PORT = 0 16 | Title = "" 17 | FaviconicoUrl = "" 18 | SECRETKEY []byte 19 | DBDRIVER = "" 20 | DBURL = "" 21 | DBDATAURL = "" 22 | DbName = "" 23 | KeyDb = "" 24 | UserEmail = "" 25 | UserPassword = "" 26 | DownLoadImage = "" 27 | ImgUrl = "" 28 | VideoTypes = "" 29 | UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36" 30 | ) 31 | 32 | // Load the server PORT 33 | func Load() { 34 | var err error 35 | err = godotenv.Load(EnvFile) 36 | if err != nil { 37 | return 38 | } 39 | PORT, err = strconv.Atoi(os.Getenv("API_PORT")) 40 | if err != nil { 41 | PORT = 9000 42 | } 43 | Env := os.Getenv("Env") 44 | Title = os.Getenv("Title") 45 | FaviconicoUrl = os.Getenv("FaviconicoUrl") 46 | if Env == "Debug" { 47 | DBDATAURL = fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/?charset=utf8mb4", os.Getenv("DB_USER"), os.Getenv("DB_PASSWORD_Debug")) 48 | DBURL = fmt.Sprintf("%s:%s@/%s", 49 | os.Getenv("DB_USER"), 50 | os.Getenv("DB_PASSWORD_Debug"), 51 | os.Getenv("DB_NAME"), 52 | ) + "?charset=utf8mb4&parseTime=true&loc=Asia%2FShanghai" 53 | } else { 54 | DBDATAURL = fmt.Sprintf("%s:%s@/?charset=utf8mb4", os.Getenv("DB_USER"), os.Getenv("DB_PASSWORD_Release")) 55 | //当数据库为docker,注意替换:fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306) 56 | DBURL = fmt.Sprintf("%s:%s@/%s", 57 | os.Getenv("DB_USER"), 58 | os.Getenv("DB_PASSWORD_Release"), 59 | os.Getenv("DB_NAME"), 60 | ) + "?charset=utf8mb4&parseTime=true&loc=Asia%2FShanghai" 61 | } 62 | DBDRIVER = os.Getenv("DB_DRIVER") 63 | SECRETKEY = []byte(os.Getenv("API_SECRET")) 64 | DbName = os.Getenv("DbName") 65 | KeyDb = os.Getenv("KeyDb") 66 | UserEmail = os.Getenv("UserEmail") 67 | UserPassword = os.Getenv("UserPassword") 68 | DownLoadImage = os.Getenv("DownLoadImage") 69 | ImgUrl = os.Getenv("ImgUrl") 70 | VideoTypes = os.Getenv("VideoTypes") 71 | } 72 | 73 | // 获取配置 74 | func GetConfig() models.Config { 75 | config := models.Config{ 76 | Title: Title, 77 | DownLoadImage: DownLoadImage, 78 | ImgUrl: ImgUrl, 79 | KeyDb: KeyDb, 80 | FaviconicoUrl: FaviconicoUrl, 81 | VideoTypes: VideoTypes, 82 | } 83 | return config 84 | } 85 | 86 | // 设置配置 87 | func SetConfig(config models.Config) { 88 | Title = config.Title 89 | DownLoadImage = config.DownLoadImage 90 | ImgUrl = config.ImgUrl 91 | KeyDb = config.KeyDb 92 | FaviconicoUrl = config.FaviconicoUrl 93 | VideoTypes = config.VideoTypes 94 | } 95 | 96 | // 保存配置 97 | func SaveConfig(config models.Config) (models.Config, error) { 98 | b, err := os.ReadFile(EnvFile) 99 | if err != nil { 100 | return models.Config{}, err 101 | } 102 | data := strings.ReplaceAll(string(b), "Title="+Title, "Title="+config.Title) 103 | data = strings.ReplaceAll(data, "DownLoadImage="+DownLoadImage, "DownLoadImage="+config.DownLoadImage) 104 | data = strings.ReplaceAll(data, "ImgUrl="+ImgUrl, "ImgUrl="+config.ImgUrl) 105 | data = strings.ReplaceAll(data, "FaviconicoUrl="+FaviconicoUrl, "FaviconicoUrl="+config.FaviconicoUrl) 106 | data = strings.ReplaceAll(data, "KeyDb="+KeyDb, "KeyDb="+config.KeyDb) 107 | data = strings.ReplaceAll(data, "VideoTypes="+VideoTypes, "VideoTypes="+config.VideoTypes) 108 | content := []byte(data) 109 | err = os.WriteFile(EnvFile, content, 0644) 110 | if err != nil { 111 | return models.Config{}, err 112 | } 113 | SetConfig(config) 114 | return GetConfig(), nil 115 | 116 | } 117 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.3' 2 | services: 3 | onelist: 4 | restart: always 5 | container_name: onelist 6 | image: 'msterzhang/onelist:latest' 7 | volumes: 8 | - '/root/onelist/config:/config' 9 | ports: 10 | - '5245:5245' 11 | environment: 12 | - PUID=0 13 | - PGID=0 14 | - TZ=Asia/Shanghai 15 | extra_hosts: 16 | - 'api.themoviedb.org:13.224.161.90' 17 | - 'api.themoviedb.org:13.35.67.86' 18 | - 'api.themoviedb.org:13.249.175.212' 19 | - 'api.themoviedb.org:13.35.161.120' 20 | - 'image.themoviedb.org:104.16.61.155' 21 | - 'www.themoviedb.org:54.192.151.79' 22 | -------------------------------------------------------------------------------- /docker/rootfs/etc/s6-overlay/s6-rc.d/init-config/run: -------------------------------------------------------------------------------- 1 | #!/usr/bin/with-contenv bash 2 | 3 | cd /config 4 | 5 | chown -R ${PUID}:${PGID} \ 6 | /config \ 7 | /app 8 | 9 | if [ ! -f /config/config.env ]; then 10 | s6-setuidgid ${PUID}:${PGID} /app/onelist -run config 11 | s6-setuidgid ${PUID}:${PGID} /app/onelist -run admin 12 | fi 13 | -------------------------------------------------------------------------------- /docker/rootfs/etc/s6-overlay/s6-rc.d/init-config/type: -------------------------------------------------------------------------------- 1 | oneshot -------------------------------------------------------------------------------- /docker/rootfs/etc/s6-overlay/s6-rc.d/init-config/up: -------------------------------------------------------------------------------- 1 | /etc/s6-overlay/s6-rc.d/init-config/run -------------------------------------------------------------------------------- /docker/rootfs/etc/s6-overlay/s6-rc.d/svc-onelist/dependencies.d/init-config: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msterzhang/onelist/839c48e2d8f70c01e592be8500b0e5560ea35f9d/docker/rootfs/etc/s6-overlay/s6-rc.d/svc-onelist/dependencies.d/init-config -------------------------------------------------------------------------------- /docker/rootfs/etc/s6-overlay/s6-rc.d/svc-onelist/finish: -------------------------------------------------------------------------------- 1 | #!/usr/bin/with-contenv bash 2 | # shellcheck shell=bash 3 | 4 | pkill -f '/app/onelist -run server' -------------------------------------------------------------------------------- /docker/rootfs/etc/s6-overlay/s6-rc.d/svc-onelist/run: -------------------------------------------------------------------------------- 1 | #!/usr/bin/with-contenv bash 2 | 3 | cd /config 4 | 5 | exec s6-setuidgid ${PUID}:${PGID} /app/onelist -run server -------------------------------------------------------------------------------- /docker/rootfs/etc/s6-overlay/s6-rc.d/svc-onelist/type: -------------------------------------------------------------------------------- 1 | longrun -------------------------------------------------------------------------------- /docker/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/init-config: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msterzhang/onelist/839c48e2d8f70c01e592be8500b0e5560ea35f9d/docker/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/init-config -------------------------------------------------------------------------------- /docker/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/svc-onelist: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msterzhang/onelist/839c48e2d8f70c01e592be8500b0e5560ea35f9d/docker/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/svc-onelist -------------------------------------------------------------------------------- /docs/docker_conpose_install.md: -------------------------------------------------------------------------------- 1 | ### 1.主机新建一个文件夹: 2 | 3 | /root/onelist 4 | 5 | 文件夹中创建一个`/root/onelist/docker-compose.yml`文件,写入以下内容 6 | ``` 7 | version: '3.3' 8 | services: 9 | onelist: 10 | restart: always 11 | container_name: onelist 12 | image: 'msterzhang/onelist:latest' 13 | volumes: 14 | - '/root/onelist/config:/config' 15 | ports: 16 | - '5245:5245' 17 | environment: 18 | - PUID=0 19 | - PGID=0 20 | - UMASK=022 21 | - TZ=Asia/Shanghai 22 | extra_hosts: 23 | - 'api.themoviedb.org:13.224.161.90' 24 | - 'api.themoviedb.org:13.35.67.86' 25 | - 'api.themoviedb.org:13.249.175.212' 26 | - 'api.themoviedb.org:13.35.161.120' 27 | - 'image.themoviedb.org:104.16.61.155' 28 | - 'www.themoviedb.org:54.192.151.79' 29 | 30 | ``` 31 | 32 | 33 | ### 2.运行命令启动项目容器 34 | ``` 35 | # 切换到docker-compose.yml所在目录 36 | cd /root/onelist 37 | 38 | # 启动项目 39 | docker-compose up -d 40 | ``` 41 | 42 | ### 3.修改配置 43 | 编辑`/root/onelist/config`目录下config.env 44 | ``` 45 | # 服务设置 46 | # 注意要改为未被占用的端口 47 | API_PORT=5245 48 | FaviconicoUrl=https://wework.qpic.cn/wwpic/818353_fizV30xbQCGPQRP_1677394564/0 49 | API_SECRET=8qQU6Uz0pgF8pYOK1huPUnk2nopM3DHi 50 | 51 | # 网站名称 52 | Title=onelist 53 | 54 | # Env有两种模式,Debug及Release,主要用在数据库为mysql时候,需要注意修改Env环境和mysql密码对应 55 | Env=Debug 56 | 57 | # 管理员账户设置,用于初始化管理员账户 58 | UserEmail=xxxx.@qq.com 59 | UserPassword=xxxxx 60 | 61 | # 下载刮削图片到本地 62 | DownLoadImage=是 63 | # 留空则表示使用本地缓存图片,否则使用https://image.tmdb.org 64 | ImgUrl= 65 | # 允许刮削alist中的视频文件类型 66 | VideoTypes=.mp4,.mkv,.flv 67 | 68 | # 数据库设置 69 | DB_DRIVER=sqlite 70 | DB_USER=root 71 | DbName=onelist 72 | 73 | # 如果上面DB_DRIVER类型为mysql,就需要正确填下以下参数 74 | DB_PASSWORD_Debug=123456 75 | DB_PASSWORD_Release=123456 76 | 77 | # TheMovieDb Key 78 | # 在https://www.themoviedb.org网站申请 79 | KeyDb=22f10ca52f109158ac7fe064ebbcf697 80 | ``` 81 | ### 4.重启项目容器 82 | ``` 83 | docker-compose up -d 84 | ``` 85 | 86 | ### 5.监控容器,有最新版onelist,自动下载安装 87 | ``` 88 | docker pull containrrr/watchtower 89 | 90 | docker run --rm -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower -c --run-once onelist 91 | ``` 92 | > 注意:进入后台后需要删除初始化的xxxx.@qq.com账号,防止被人登录 -------------------------------------------------------------------------------- /docs/docker_install.md: -------------------------------------------------------------------------------- 1 | ### 1.拉取docker镜像 2 | ``` 3 | docker pull msterzhang/onelist:latest 4 | ``` 5 | 6 | ### 2.新建一个用于保存配置相关文件的目录,比如: 7 | ``` 8 | /root/onelist/config 9 | ``` 10 | 11 | ### 3.运行 12 | ``` 13 | docker run -d --name onelist -e PUID=0 -e PGID=0 -e TZ=Asia/Shanghai -p 5245:5245 -v /root/onelist/config:/config --add-host api.themoviedb.org:13.224.161.90 msterzhang/onelist:latest 14 | ``` 15 | 16 | ### 4.修改配置 17 | 编辑`/root/onelist/config`目录下config.env 18 | ``` 19 | 20 | # 服务设置 21 | # 注意要改为未被占用的端口 22 | API_PORT=5245 23 | FaviconicoUrl=https://wework.qpic.cn/wwpic/818353_fizV30xbQCGPQRP_1677394564/0 24 | API_SECRET=8qQU6Uz0pgF8pYOK1huPUnk2nopM3DHi 25 | 26 | # 网站名称 27 | Title=onelist 28 | 29 | # Env有两种模式,Debug及Release,主要用在数据库为mysql时候,需要注意修改Env环境和mysql密码对应 30 | Env=Debug 31 | 32 | # 管理员账户设置,用于初始化管理员账户 33 | UserEmail=xxxx.@qq.com 34 | UserPassword=xxxxx 35 | 36 | # 下载刮削图片到本地 37 | DownLoadImage=是 38 | # 留空则表示使用本地缓存图片,否则使用https://image.tmdb.org 39 | ImgUrl= 40 | # 允许刮削alist中的视频文件类型 41 | VideoTypes=.mp4,.mkv,.flv 42 | 43 | # 数据库设置 44 | DB_DRIVER=sqlite 45 | DB_USER=root 46 | DbName=onelist 47 | 48 | # 如果上面DB_DRIVER类型为mysql,就需要正确填下以下参数 49 | DB_PASSWORD_Debug=123456 50 | DB_PASSWORD_Release=123456 51 | 52 | # TheMovieDb Key 53 | # 在https://www.themoviedb.org网站申请 54 | KeyDb=22f10ca52f109158ac7fe064ebbcf697 55 | ``` 56 | ### 5.重启容器,便可以访问了 57 | ``` 58 | docker restart onelist 59 | ``` 60 | ### 6.监控容器,有最新版onelist,自动下载安装 61 | ``` 62 | docker pull containrrr/watchtower 63 | 64 | docker run --rm -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower -c --run-once onelist 65 | ``` 66 | 67 | ### 7.如果刮削效果不好,可以在hosts增加dns解析: 68 | 69 | 进入运行中的Docker容器: 70 | ``` 71 | docker exec -it onelist /bin/bash 72 | ``` 73 | 编辑hosts文件: 74 | ``` 75 | vi /etc/hosts 76 | ``` 77 | 在文件的末尾添加所需的主机名和IP地址: 78 | ``` 79 | 13.224.161.90 api.themoviedb.org 80 | 104.16.61.155 image.themoviedb.org 81 | 13.35.67.86 api.themoviedb.org 82 | 54.192.151.79 www.themoviedb.org 83 | 13.225.89.239 api.thetvdb.com 84 | 13.249.175.212 api.thetvdb.com 85 | 13.35.161.120 api.thetvdb.com 86 | 13.226.238.76 api.themoviedb.org 87 | 13.35.7.102 api.themoviedb.org 88 | 13.225.103.26 api.themoviedb.org 89 | 13.226.191.85 api.themoviedb.org 90 | 13.225.103.110 api.themoviedb.org 91 | 52.85.79.89 api.themoviedb.org 92 | 13.225.41.40 api.themoviedb.org 93 | 13.226.251.88 api.themoviedb.org 94 | ``` 95 | 保存并退出文件。 96 | ``` 97 | 按Esc键,进入vim命令模式 98 | 输入 99 | :wq 100 | 回车退出 101 | ``` 102 | 退出容器: 103 | ``` 104 | exit 105 | ``` 106 | 现在,您的Docker容器的hosts文件已被修改,您可以使用新的主机名和IP地址在容器内部进行通信。 -------------------------------------------------------------------------------- /docs/imgs/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msterzhang/onelist/839c48e2d8f70c01e592be8500b0e5560ea35f9d/docs/imgs/01.png -------------------------------------------------------------------------------- /docs/imgs/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msterzhang/onelist/839c48e2d8f70c01e592be8500b0e5560ea35f9d/docs/imgs/02.png -------------------------------------------------------------------------------- /docs/imgs/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msterzhang/onelist/839c48e2d8f70c01e592be8500b0e5560ea35f9d/docs/imgs/03.png -------------------------------------------------------------------------------- /docs/imgs/wx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msterzhang/onelist/839c48e2d8f70c01e592be8500b0e5560ea35f9d/docs/imgs/wx.png -------------------------------------------------------------------------------- /docs/imgs/zfb.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msterzhang/onelist/839c48e2d8f70c01e592be8500b0e5560ea35f9d/docs/imgs/zfb.jpg -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/msterzhang/onelist 2 | 3 | go 1.20 4 | 5 | require ( 6 | github.com/dgrijalva/jwt-go v3.2.0+incompatible 7 | github.com/gin-gonic/gin v1.8.2 8 | github.com/google/uuid v1.3.0 9 | github.com/joho/godotenv v1.5.1 10 | github.com/patrickmn/go-cache v2.1.0+incompatible 11 | github.com/robfig/cron/v3 v3.0.1 12 | github.com/urfave/cli v1.22.12 13 | gorm.io/driver/mysql v1.4.7 14 | gorm.io/driver/sqlite v1.4.4 15 | gorm.io/gorm v1.24.5 16 | ) 17 | 18 | require ( 19 | github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect 20 | github.com/gin-contrib/sse v0.1.0 // indirect 21 | github.com/go-playground/locales v0.14.0 // indirect 22 | github.com/go-playground/universal-translator v0.18.0 // indirect 23 | github.com/go-playground/validator/v10 v10.11.1 // indirect 24 | github.com/go-sql-driver/mysql v1.7.0 // indirect 25 | github.com/goccy/go-json v0.9.11 // indirect 26 | github.com/jinzhu/inflection v1.0.0 // indirect 27 | github.com/jinzhu/now v1.1.5 // indirect 28 | github.com/json-iterator/go v1.1.12 // indirect 29 | github.com/leodido/go-urn v1.2.1 // indirect 30 | github.com/mattn/go-isatty v0.0.16 // indirect 31 | github.com/mattn/go-sqlite3 v1.14.15 // indirect 32 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect 33 | github.com/modern-go/reflect2 v1.0.2 // indirect 34 | github.com/pelletier/go-toml/v2 v2.0.6 // indirect 35 | github.com/russross/blackfriday/v2 v2.1.0 // indirect 36 | github.com/ugorji/go/codec v1.2.7 // indirect 37 | golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect 38 | golang.org/x/net v0.4.0 // indirect 39 | golang.org/x/sys v0.3.0 // indirect 40 | golang.org/x/text v0.5.0 // indirect 41 | google.golang.org/protobuf v1.28.1 // indirect 42 | gopkg.in/yaml.v2 v2.4.0 // indirect 43 | ) 44 | -------------------------------------------------------------------------------- /initconfig/initconfig.go: -------------------------------------------------------------------------------- 1 | package initconfig 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "os" 7 | 8 | "github.com/msterzhang/onelist/api" 9 | "github.com/msterzhang/onelist/api/database" 10 | "github.com/msterzhang/onelist/api/models" 11 | "github.com/msterzhang/onelist/api/security" 12 | "github.com/msterzhang/onelist/api/utils/tools" 13 | "github.com/msterzhang/onelist/config" 14 | ) 15 | 16 | var configEnv = ` 17 | # 服务设置 18 | # 注意要改为未被占用的端口 19 | API_PORT=5245 20 | FaviconicoUrl=https://wework.qpic.cn/wwpic/818353_fizV30xbQCGPQRP_1677394564/0 21 | API_SECRET=%s 22 | 23 | # 网站名称 24 | Title=onelist 25 | 26 | # Env有两种模式,Debug及Release,主要用在数据库为mysql时候,需要注意修改Env环境和mysql密码对应 27 | Env=Debug 28 | 29 | # 管理员账户设置,用于初始化管理员账户 30 | UserEmail=xxxx.@qq.com 31 | UserPassword=xxxxx 32 | 33 | # 下载刮削图片到本地 34 | DownLoadImage=是 35 | # 留空则表示使用本地缓存图片,否则使用https://image.tmdb.org 36 | ImgUrl=https://image.tmdb.org 37 | # 允许刮削alist中的视频文件类型 38 | VideoTypes=.mp4,.mkv,.flv 39 | 40 | # 数据库设置 41 | DB_DRIVER=sqlite 42 | DB_USER=root 43 | DbName=onelist 44 | 45 | # 如果上面DB_DRIVER类型为mysql,就需要正确填下以下参数 46 | DB_PASSWORD_Debug=123456 47 | DB_PASSWORD_Release=123456 48 | 49 | # TheMovieDb Key 50 | # 在https://www.themoviedb.org网站申请 51 | KeyDb=22f10ca52f109158ac7fe064ebbcf697 52 | ` 53 | 54 | func InitConfigEnv() error { 55 | content := []byte(fmt.Sprintf(configEnv, tools.RandStringRunes(32))) 56 | err := os.WriteFile("config.env", content, 0644) 57 | if err != nil { 58 | return err 59 | } 60 | return nil 61 | } 62 | 63 | func AdminData() (models.User, error) { 64 | api.InitServer() 65 | db := database.NewDb() 66 | user := models.User{} 67 | err := db.Model(&models.User{}).Where("user_email = ?", config.UserEmail).First(&user).Error 68 | if err != nil { 69 | return models.User{}, err 70 | } 71 | pwd, err := security.DecodePassword(user.UserPassword) 72 | if err != nil { 73 | log.Fatal(err) 74 | } 75 | user.UserPassword = pwd 76 | return user, nil 77 | } 78 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "os" 7 | 8 | "github.com/msterzhang/onelist/api" 9 | "github.com/msterzhang/onelist/initconfig" 10 | "github.com/urfave/cli" 11 | ) 12 | 13 | func main() { 14 | app := &cli.App{ 15 | Name: "onelist", 16 | Usage: "一个类似emby的专注于刮削alist聚合网盘形成影视媒体库的程序。", 17 | Flags: []cli.Flag{ 18 | &cli.StringFlag{ 19 | Name: "run, r", 20 | Usage: "首先运行onelist -run config初始化项目(谨慎操作,否则会覆盖你已有配置文件),会生成config.env配置文件,按要求修改完毕后,运行onelist -run server便可以启动项目,onelist -run admin可查询管理员账户及密码。", 21 | }, 22 | }, 23 | Action: func(c *cli.Context) error { 24 | run := c.String("run") 25 | if run == "config" { 26 | err := initconfig.InitConfigEnv() 27 | if err != nil { 28 | log.Fatal(err) 29 | } 30 | fmt.Println("初始化成功!") 31 | fmt.Println("修改完config.env配置文件后,运行onelist -run server便可启动项目,忘记密码运行onelist -run admin可查看管理员账户!") 32 | } else if run == "admin" { 33 | user, err := initconfig.AdminData() 34 | if err != nil { 35 | log.Fatal(err) 36 | } 37 | data := fmt.Sprintf("账号:%s 密码:%s", user.UserEmail, user.UserPassword) 38 | fmt.Println(data) 39 | } else { 40 | api.Run() 41 | } 42 | return nil 43 | }, 44 | } 45 | err := app.Run(os.Args) 46 | if err != nil { 47 | log.Fatal(err) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /plugins/alist/mode.go: -------------------------------------------------------------------------------- 1 | package alist 2 | 3 | import "time" 4 | 5 | type AlistRspLogin struct { 6 | Code int `json:"code"` 7 | Message string `json:"message"` 8 | Data struct { 9 | Token string `json:"token"` 10 | } `json:"data"` 11 | } 12 | 13 | // alist文件体 14 | type Content struct { 15 | Name string `json:"name"` 16 | ContentHash string `json:"content_hash"` 17 | Size int `json:"size"` 18 | IsDir bool `json:"is_dir"` 19 | Modified time.Time `json:"modified"` 20 | Sign string `json:"sign"` 21 | Thumb string `json:"thumb"` 22 | Type int `json:"type"` 23 | } 24 | 25 | // alist获取目录的 26 | type AListRspData struct { 27 | Code int `json:"code"` 28 | Message string `json:"message"` 29 | Data struct { 30 | Content []Content `json:"content"` 31 | Total int `json:"total"` 32 | Readme string `json:"readme"` 33 | Write bool `json:"write"` 34 | Provider string `json:"provider"` 35 | } `json:"data"` 36 | } 37 | 38 | type AliOpenForm struct{ 39 | File string `json:"file"` 40 | GalleryUid string `json:"gallery_uid"` 41 | } 42 | 43 | 44 | // alist 阿里云open资源 45 | type AliOpenVideo struct { 46 | Code int `json:"code"` 47 | Message string `json:"message"` 48 | Data struct { 49 | DriveID string `json:"drive_id"` 50 | FileID string `json:"file_id"` 51 | VideoPreviewPlayInfo struct { 52 | Category string `json:"category"` 53 | LiveTranscodingSubtitleTaskList []struct { 54 | Language string `json:"language"` 55 | Status string `json:"status"` 56 | URL string `json:"url"` 57 | } `json:"live_transcoding_subtitle_task_list"` 58 | LiveTranscodingTaskList []struct { 59 | Stage string `json:"stage"` 60 | Status string `json:"status"` 61 | TemplateHeight int `json:"template_height"` 62 | TemplateID string `json:"template_id"` 63 | TemplateName string `json:"template_name"` 64 | TemplateWidth int `json:"template_width"` 65 | URL string `json:"url"` 66 | } `json:"live_transcoding_task_list"` 67 | Meta struct { 68 | Duration float64 `json:"duration"` 69 | Height int `json:"height"` 70 | Width int `json:"width"` 71 | } `json:"meta"` 72 | } `json:"video_preview_play_info"` 73 | } `json:"data"` 74 | } 75 | -------------------------------------------------------------------------------- /plugins/thedb/download.go: -------------------------------------------------------------------------------- 1 | package thedb 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | "log" 7 | "net/http" 8 | "os" 9 | 10 | "github.com/msterzhang/onelist/api/utils/dir" 11 | ) 12 | 13 | var imgpath = "images" 14 | var imgcdn = "https://tmdb-image-prod.b-cdn.net" 15 | 16 | var dirs = []string{"w220_and_h330_face", "w440_and_h660_face", "w600_and_h900_bestv2", "w710_and_h400_multi_faces", "w227_and_h127_bestv2", "w1920_and_h1080_bestv2", "w355_and_h200_multi_faces"} 17 | 18 | // 下载竖向海报图 19 | var keys = []string{"w220_and_h330_face", "w440_and_h660_face", "w600_and_h900_bestv2"} 20 | 21 | // 电视分季信息图片 22 | var keysSeason = []string{"w220_and_h330_face"} 23 | 24 | // 电视分集信息图片 25 | var keysEpisode = []string{"w227_and_h127_bestv2", "w710_and_h400_multi_faces", "w1920_and_h1080_bestv2"} 26 | 27 | // 下载横向海报图及背景图 28 | var keysBackImge = []string{"w355_and_h200_multi_faces", "w1920_and_h1080_bestv2"} 29 | 30 | // 初始化图片保存目录 31 | func initDir() { 32 | for _, item := range dirs { 33 | imgsPath := imgpath + "/" + item 34 | if !dir.DirExists(imgsPath) { 35 | err := os.MkdirAll(imgsPath, os.ModePerm) 36 | if err != nil { 37 | log.Panic("创建图片保存文件夹失败!") 38 | } 39 | } 40 | } 41 | } 42 | 43 | // 下载电视剧及电影竖向海报图 44 | func DownImages(id string) error { 45 | if len(id) == 0 { 46 | return nil 47 | } 48 | initDir() 49 | for _, key := range keys { 50 | url := fmt.Sprintf("%s/t/p/%s/%s", imgcdn, key, id) 51 | file := fmt.Sprintf("%s/%s/%s", imgpath, key, id) 52 | if dir.FileExists(file) { 53 | continue 54 | } 55 | err := Download(url, file) 56 | if err != nil { 57 | continue 58 | } 59 | } 60 | return nil 61 | } 62 | 63 | // 下载电视分季所需图片 64 | func DownSeasonImages(id string) error { 65 | if len(id) == 0 { 66 | return nil 67 | } 68 | initDir() 69 | for _, key := range keysSeason { 70 | url := fmt.Sprintf("%s/t/p/%s/%s", imgcdn, key, id) 71 | file := fmt.Sprintf("%s/%s/%s", imgpath, key, id) 72 | if dir.FileExists(file) { 73 | continue 74 | } 75 | err := Download(url, file) 76 | if err != nil { 77 | continue 78 | } 79 | } 80 | return nil 81 | } 82 | 83 | // 下载电视分集所需图片 84 | func DownEpisodeImages(id string) error { 85 | if len(id) == 0 { 86 | return nil 87 | } 88 | initDir() 89 | for _, key := range keysEpisode { 90 | url := fmt.Sprintf("%s/t/p/%s/%s", imgcdn, key, id) 91 | file := fmt.Sprintf("%s/%s/%s", imgpath, key, id) 92 | if dir.FileExists(file) { 93 | continue 94 | } 95 | err := Download(url, file) 96 | if err != nil { 97 | continue 98 | } 99 | } 100 | return nil 101 | } 102 | 103 | // 下载影人图片 104 | func DownPersonImage(id string) error { 105 | if len(id) == 0 { 106 | return nil 107 | } 108 | initDir() 109 | url := fmt.Sprintf("%s/t/p/%s/%s", imgcdn, "w220_and_h330_face", id) 110 | file := fmt.Sprintf("%s/%s/%s", imgpath, "w220_and_h330_face", id) 111 | if dir.FileExists(file) { 112 | return nil 113 | } 114 | err := Download(url, file) 115 | if err != nil { 116 | return err 117 | } 118 | return nil 119 | } 120 | 121 | // 下载封面及大背景图 122 | func DownBackImage(id string) error { 123 | if len(id) == 0 { 124 | return nil 125 | } 126 | initDir() 127 | for _, key := range keysBackImge { 128 | url := fmt.Sprintf("%s/t/p/%s/%s", imgcdn, key, id) 129 | file := fmt.Sprintf("%s/%s/%s", imgpath, key, id) 130 | if dir.FileExists(file) { 131 | continue 132 | } 133 | err := Download(url, file) 134 | if err != nil { 135 | continue 136 | } 137 | } 138 | return nil 139 | } 140 | 141 | // 下载图片 142 | func Download(url string, fileName string) error { 143 | req, err := http.NewRequest("GET", url, nil) 144 | if err != nil { 145 | return err 146 | } 147 | client := http.Client{ 148 | Timeout: timeOut, 149 | } 150 | resp, err := client.Do(req) 151 | if err != nil { 152 | return err 153 | } 154 | defer resp.Body.Close() 155 | file, err := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE, 0666) 156 | if err != nil { 157 | return err 158 | } 159 | defer file.Close() 160 | io.Copy(file, resp.Body) 161 | return nil 162 | } 163 | -------------------------------------------------------------------------------- /plugins/thedb/model.go: -------------------------------------------------------------------------------- 1 | package thedb 2 | 3 | type TheVideo struct { 4 | BackdropPath string `json:"backdrop_path"` 5 | FirstAirDate string `json:"first_air_date"` 6 | GenreIds []int `json:"genre_ids"` 7 | ID int `json:"id"` 8 | Title string `json:"title"` 9 | Name string `json:"name"` 10 | OriginCountry []string `json:"origin_country"` 11 | OriginalLanguage string `json:"original_language"` 12 | OriginalName string `json:"original_name"` 13 | Overview string `json:"overview"` 14 | Popularity float64 `json:"popularity"` 15 | PosterPath string `json:"poster_path"` 16 | VoteAverage float64 `json:"vote_average"` 17 | VoteCount int `json:"vote_count"` 18 | } 19 | 20 | type ThedbSearchRsp struct { 21 | Page int `json:"page"` 22 | Results []TheVideo `json:"results"` 23 | TotalPages int `json:"total_pages"` 24 | TotalResults int `json:"total_results"` 25 | } 26 | -------------------------------------------------------------------------------- /plugins/watch/watch.go: -------------------------------------------------------------------------------- 1 | package watch 2 | 3 | import ( 4 | "errors" 5 | 6 | "github.com/msterzhang/onelist/api/database" 7 | "github.com/msterzhang/onelist/api/models" 8 | "github.com/msterzhang/onelist/api/utils/dir" 9 | "github.com/msterzhang/onelist/plugins/alist" 10 | "github.com/msterzhang/onelist/plugins/thedb" 11 | "gorm.io/gorm" 12 | ) 13 | 14 | // 重新查询挂载目录中所有文件,未在影库中找到的就开始刮削 15 | func RunWork(work models.Work) { 16 | db := database.NewDb() 17 | if work.Watching { 18 | gallery := models.Gallery{} 19 | err := db.Model(&models.Gallery{}).Where("gallery_uid = ?", work.GalleryUid).First(&gallery).Error 20 | if err != nil { 21 | return 22 | } 23 | var files = []string{} 24 | if gallery.IsAlist { 25 | files, err = alist.GetAlistFilesPath(work.Path, true, gallery) 26 | if err != nil { 27 | return 28 | } 29 | } else { 30 | files = dir.GetFilesByPath(work.Path) 31 | } 32 | for _, file := range files { 33 | if gallery.GalleryType == "tv" { 34 | episode := models.Episode{} 35 | err := db.Model(&models.Episode{}).Where("url = ?", file).First(&episode).Error 36 | if errors.Is(err, gorm.ErrRecordNotFound) { 37 | _, err = thedb.RunTheTvWork(file, gallery.GalleryUid) 38 | if err != nil { 39 | continue 40 | } 41 | } 42 | } else { 43 | themovie := models.TheMovie{} 44 | err = db.Model(&models.TheMovie{}).Where("url = ?", file).First(&themovie).Error 45 | if errors.Is(err, gorm.ErrRecordNotFound) { 46 | _, err = thedb.RunTheMovieWork(file, gallery.GalleryUid) 47 | if err != nil { 48 | continue 49 | } 50 | } 51 | } 52 | } 53 | } 54 | } 55 | 56 | // 监控 57 | func WatchPath() { 58 | db := database.NewDb() 59 | works := []models.Work{} 60 | err := db.Model(&models.Work{}).Find(&works).Error 61 | if err != nil { 62 | return 63 | } 64 | for _, work := range works { 65 | RunWork(work) 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /plugins/watch/work.go: -------------------------------------------------------------------------------- 1 | package watch 2 | 3 | import ( 4 | "errors" 5 | 6 | "github.com/msterzhang/onelist/api/database" 7 | "github.com/msterzhang/onelist/api/models" 8 | "gorm.io/gorm" 9 | ) 10 | 11 | // 自动给影库添加封面 12 | func UpdateGalleryImage() error { 13 | db := database.NewDb() 14 | gallerys := []models.Gallery{} 15 | err := db.Model(&models.Gallery{}).Find(&gallerys).Error 16 | if err != nil { 17 | return err 18 | } 19 | for _, gallery := range gallerys { 20 | if len(gallery.Image) == 0 { 21 | if gallery.GalleryType == "movie" { 22 | themovie := models.TheMovie{} 23 | err := db.Model(&models.TheMovie{}).Where("gallery_uid = ?", gallery.GalleryUid).First(&themovie).Error 24 | if errors.Is(err, gorm.ErrRecordNotFound) { 25 | return nil 26 | } 27 | if err != nil { 28 | return err 29 | } 30 | gallery.Image = themovie.BackdropPath 31 | err = db.Model(&models.Gallery{}).Where("id = ?", gallery.Id).Select("*").Updates(&gallery).Error 32 | if err != nil { 33 | return err 34 | } 35 | continue 36 | } 37 | thetv := models.TheTv{} 38 | err := db.Model(&models.TheTv{}).Where("gallery_uid = ?", gallery.GalleryUid).First(&thetv).Error 39 | if errors.Is(err, gorm.ErrRecordNotFound) { 40 | return nil 41 | } 42 | if err != nil { 43 | return err 44 | } 45 | gallery.Image = thetv.BackdropPath 46 | err = db.Model(&models.Gallery{}).Where("id = ?", gallery.Id).Select("*").Updates(&gallery).Error 47 | if err != nil { 48 | return err 49 | } 50 | } 51 | } 52 | return nil 53 | } 54 | -------------------------------------------------------------------------------- /public/README.md: -------------------------------------------------------------------------------- 1 | ## onelist-web 2 | https://github.com/msterzhang/onelist-web/releases -------------------------------------------------------------------------------- /public/public.go: -------------------------------------------------------------------------------- 1 | package public 2 | 3 | import "embed" 4 | 5 | //go:embed * 6 | var Public embed.FS 7 | -------------------------------------------------------------------------------- /wrapper/zcc-arm64: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | zig cc -target aarch64-windows-gnu $@ 3 | -------------------------------------------------------------------------------- /wrapper/zcxx-arm64: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | zig c++ -target aarch64-windows-gnu $@ 3 | --------------------------------------------------------------------------------