Skip to content

Commit

Permalink
feat: Add download_filename_type to channel
Browse files Browse the repository at this point in the history
1. Only control fields are added, and the file name logic for downloading has not yet been implemented
2. Swagger is not included
3. Channel information display is not included
  • Loading branch information
rakuyoMo committed Nov 27, 2024
1 parent e6c97cf commit af4c3d8
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 10 deletions.
1 change: 1 addition & 0 deletions app/controllers/api/apps/upload_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def channel_params
append_present_value_from_params(obj, :slug)
append_present_value_from_params(obj, :password)
append_present_value_from_params(obj, :git_url)
append_present_value_from_params(obj, :download_filename_type)
obj
}.call
end
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/api/channels_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def set_channel
end

def channel_params
@channel_params ||= params.permit(:name, :slug, :device_type, :bundle_id, :password, :git_url)
@channel_params ||= params.permit(
:name, :slug, :device_type, :bundle_id, :password, :git_url, :download_filename_type
)
end
end
2 changes: 1 addition & 1 deletion app/controllers/channels_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def set_channel
def channel_params
params.require(:channel).permit(
:scheme_id, :name, :device_type, :bundle_id,
:slug, :password, :git_url
:slug, :password, :git_url, :download_filename_type
)
end

Expand Down
12 changes: 12 additions & 0 deletions app/models/channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class Channel < ApplicationRecord
macos: 'macOS', windows: 'Windows', linux: 'Linux'
}

enum :download_filename_type, {
system: 'system',
original: 'original'
}

delegate :count, to: :enabled_web_hooks, prefix: true
delegate :count, to: :available_web_hooks, prefix: true
delegate :app, to: :scheme
Expand All @@ -28,6 +33,9 @@ class Channel < ApplicationRecord
validates :name, presence: true
validates :slug, uniqueness: true
validates :device_type, presence: true, inclusion: { in: self.device_types.keys }
validates :download_filename_type, presence: true, inclusion: { in: self.download_filename_types.keys }

before_validation :set_default_download_filename_type, on: :create

def latest_release
releases.last
Expand Down Expand Up @@ -143,4 +151,8 @@ def recently_release_cache_key
def delete_app_recently_releases_cache
Rails.cache.delete(recently_release_cache_key)
end

def set_default_download_filename_type
self.download_filename_type ||= Channel.download_filename_types.keys.first
end
end
10 changes: 3 additions & 7 deletions app/models/release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,9 @@ def file_extname
end

def download_filename
if original_filename.present?
original_filename
else
[
channel.slug, release_version, build_version, created_at.strftime('%Y%m%d%H%M')
].join('_') + file_extname
end
[
channel.slug, release_version, build_version, created_at.strftime('%Y%m%d%H%M')
].join('_') + file_extname
end

def empty_changelog(use_default_changelog = true)
Expand Down
3 changes: 2 additions & 1 deletion app/serializers/channel_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

class ChannelSerializer < ApplicationSerializer
attributes :id, :slug, :name, :device_type, :bundle_id, :git_url, :has_password, :key
attributes :id, :slug, :name, :device_type, :bundle_id, :git_url, :has_password,
:key, :download_filename_type

def has_password
object.password.present?
Expand Down
1 change: 1 addition & 0 deletions app/views/channels/_form.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ruby:
= f.input :scheme_id, as: :hidden, input_html: { value: params[:scheme_id] }
= f.input :name, required: true
= f.input :device_type, collection: Channel.device_types, label_method: :last, value_method: :first, selected: channel.device_type ? channel.device_type : Channel.device_types.first
= f.input :download_filename_type, collection: Channel.download_filename_types, label_method: :last, value_method: :first, selected: channel.download_filename_type ? channel.download_filename_type : Channel.download_filename_types.first
= f.input :bundle_id
= f.input :git_url
= f.input :slug
Expand Down
2 changes: 2 additions & 0 deletions config/locales/simple_form/simple_form.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ en:
git_url: Git URL
slug: Slug
password: Password
download_filename_type: Download filename type
release:
file: File
release_version: Release version
Expand Down Expand Up @@ -108,6 +109,7 @@ en:
git_url: Git URL, for example, the repo URL of Github, Gitlab or self-host.
slug: A slug is the part of a URL that identifies a particular page on a website in an easy-to-read form.
password: Need password by fill it when user is not log in.
download_filename_type: Download file name generation rules.
release:
file: Support iOS, Android, HarmonyOS, macOS, Windows and Linux binary file.
release_version: It is recommended to name the main version <a href="https://semver.org/lang/zh-CN/">X.Y.Z semantic version</a>
Expand Down
2 changes: 2 additions & 0 deletions config/locales/simple_form/simple_form.zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ zh-CN:
git_url: Git 仓库地址
slug: 唯一地址
password: 访问密码
download_filename_type: 下载文件文件名
release:
file: 应用文件
release_version: 产品版本
Expand Down Expand Up @@ -109,6 +110,7 @@ zh-CN:
git_url: Git 项目地址,填写 Github 或 Gitlab 或其他自建地址
slug: URL 的唯一标识
password: 设置后对非登录用户会要求输入密码
download_filename_type: 下载文件文件名的生成规则
release:
file: 支持 iOS、Android、HarmonyOS、macOS、Windows、Linux 各种应用类型的文件
release_version: 应用对外公布的主版本号,推荐使用 <a href="https://semver.org/lang/zh-CN/">X.Y.Z 语义化版本</a>命名
Expand Down
1 change: 1 addition & 0 deletions config/locales/zealot/api.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ en:
bundle_id: identifier valid check, set `*` skip (`bundle_id` for iOS, `package name` for Android)
git_url: Git repository URL
password: Enable password visit
download_filename_type: Download filename type
release_options:
description: App's build metadata form data
properties:
Expand Down
1 change: 1 addition & 0 deletions config/locales/zealot/api.zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ zh-CN:
bundle_id: 包名校验, 默认是 `*` 不做校验 (iOS 指的是 bundle_id,Android 指的是 package name)
git_url: Git 仓库地址
password: 密码访问
download_filename_type: 下载文件的文件名生成规则
release_options:
description: 应用版本元信息表单字段结构
properties:
Expand Down
1 change: 1 addition & 0 deletions config/locales/zealot/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ en:
slug: Slug
password: Visit password
git_url: Git URL
download_filename_type: Download filename type
match_rule: Match Rule %{value}
wildmatch: (wild match)
total_releases: Total uploads
Expand Down
1 change: 1 addition & 0 deletions config/locales/zealot/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ zh-CN:
slug: 唯一地址
password: 访问密码
git_url: Git 仓库地址
download_filename_type: 下载文件的文件名生成规则
match_rule: 匹配模式 %{value}
wildmatch: (不限制上传包的包名)
total_releases: 上传版本
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddDownloadFileTypeToChannel < ActiveRecord::Migration[7.1]
def change
add_column :channels, :download_filename_type, :string, null: true
end
end
1 change: 1 addition & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
t.string "git_url"
t.string "password"
t.string "key"
t.string "download_filename_type", null: false
t.index ["bundle_id"], name: "index_channels_on_bundle_id"
t.index ["device_type"], name: "index_channels_on_device_type"
t.index ["name"], name: "index_channels_on_name"
Expand Down

0 comments on commit af4c3d8

Please sign in to comment.