Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

允许下载文件的名称与上传文件的名称保持一致 #1744

Merged
merged 20 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3f163c6
feat: Try adding `use_original_filename` at the logical level
rakuyoMo Nov 27, 2024
f04ea75
feat: Try adding `use_original_filename` to web page
rakuyoMo Nov 27, 2024
90984a1
style: Add line breaks
rakuyoMo Nov 27, 2024
ab48b71
Merge branch 'develop' into feature/original-file-name
rakuyoMo Nov 27, 2024
c1832b4
feat: Delete ToDo
rakuyoMo Nov 27, 2024
e6c97cf
refactor: Remove `use_original_filename`
rakuyoMo Nov 27, 2024
af4c3d8
feat: Add `download_filename_type` to channel
rakuyoMo Nov 27, 2024
83add9f
feat: Add `download_filename_type` to channels metadata
rakuyoMo Nov 27, 2024
1cbfdd1
feat: Added logic to use the original file name when downloading
rakuyoMo Nov 27, 2024
45e97cd
feat: Add `download_filename_type` to swagger
rakuyoMo Nov 27, 2024
f915ac1
Merge branch 'develop' into feature/original-file-name
rakuyoMo Nov 28, 2024
0d63c70
feat: Update local text
rakuyoMo Nov 28, 2024
6df8417
refactor: Adjust the logic of processing the file name of the downloa…
rakuyoMo Nov 28, 2024
55d4671
refactor: Rename `download_filename_type` and adjust the default valu…
rakuyoMo Nov 28, 2024
c3c3f89
feat: Add more descriptions of the file name types for downloaded fil…
rakuyoMo Nov 28, 2024
5e7e502
feat: Optimize text and prompts
rakuyoMo Nov 28, 2024
9ed480f
feat: Optimize text and prompts
rakuyoMo Nov 29, 2024
6ff8cf5
feat: Added `download_filename_type` value for old data
rakuyoMo Nov 29, 2024
7bc1e20
Merge branch 'develop' into feature/original-file-name
rakuyoMo Nov 30, 2024
3297ec1
refactor: Improve the implementation of `AddDownloadFileTypeToChannel`
rakuyoMo Nov 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 14 additions & 0 deletions app/models/channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ class Channel < ApplicationRecord
macos: 'macOS', windows: 'Windows', linux: 'Linux'
}

DEFAULT_DOWNLOAD_FILENAME_TYPE = :version_datetime

enum :download_filename_type, {
version_datetime: 'version_datetime',
original_filename: 'original_filename'
}

delegate :count, to: :enabled_web_hooks, prefix: true
delegate :count, to: :available_web_hooks, prefix: true
delegate :app, to: :scheme
Expand All @@ -28,6 +35,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 +153,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 ||= DEFAULT_DOWNLOAD_FILENAME_TYPE
end
end
25 changes: 22 additions & 3 deletions app/models/release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,14 @@ def file_extname
end

def download_filename
[
channel.slug, release_version, build_version, created_at.strftime('%Y%m%d%H%M')
].join('_') + file_extname
case channel.download_filename_type.downcase.to_sym
when :version_datetime
version_datetime_filename
when :original_filename
original_filename
else
default_filename
end
end

def empty_changelog(use_default_changelog = true)
Expand Down Expand Up @@ -318,4 +323,18 @@ def enabled_validate_bundle_id?
def retained_build_job
RetainedBuildsJob.perform_later(channel)
end

def original_filename
file? ? file.identifier : default_filename
end

def version_datetime_filename
[
channel.slug, release_version, build_version, created_at.strftime('%Y%m%d%H%M')
].join('_') + file_extname
end

def default_filename
version_datetime_filename
end
end
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::DEFAULT_DOWNLOAD_FILENAME_TYPE
= f.input :bundle_id
= f.input :git_url
= f.input :slug
Expand Down
4 changes: 4 additions & 0 deletions app/views/channels/_metadata.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
.d-flex.flex-column.border-bottom.py-2.px-3
span.font-weight-bold = @channel.releases.count
span.text-muted = t('channels.show.total_releases')
.d-flex.flex-column.border-bottom.py-2.px-3
span.font-weight-bold title=t("channels.show.download_filename_type_item.#{@channel.download_filename_type}") data-bs-toggle="tooltip" data-bs-custom-class="default-tooltip" data-bs-placement="left"
= @channel.download_filename_type
span.text-muted = t("channels.show.download_filename_type")
.d-flex.flex-column.py-2.px-3.mb-0
span.font-weight-bold = @channel.key
span.text-muted = t('channels.show.channel_key')
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 file name 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 file name 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
4 changes: 4 additions & 0 deletions config/locales/zealot/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ en:
slug: Slug
password: Visit password
git_url: Git URL
download_filename_type: Download filename rule
download_filename_type_item:
version_datetime: '{channel_slug}_{release_version}_{build_version}_{datetime}.{ext}'
original_filename: Use the original file name of the uploaded file
match_rule: Match Rule %{value}
wildmatch: (wild match)
total_releases: Total uploads
Expand Down
4 changes: 4 additions & 0 deletions config/locales/zealot/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ zh-CN:
slug: 唯一地址
password: 访问密码
git_url: Git 仓库地址
download_filename_type: 下载文件名规则
download_filename_type_item:
version_datetime: '{channel_slug}_{release_version}_{build_version}_{datetime}.{ext}'
original_filename: 使用上传文件的文件名
match_rule: 匹配模式 %{value}
wildmatch: (不限制上传包的包名)
total_releases: 上传版本
Expand Down
16 changes: 16 additions & 0 deletions db/migrate/20241127143631_add_download_file_type_to_channel.rb
rakuyoMo marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

class AddDownloadFileTypeToChannel < ActiveRecord::Migration[7.2]
def change
rakuyoMo marked this conversation as resolved.
Show resolved Hide resolved
add_column :channels, :download_filename_type, :string

reversible do |dir|
dir.up do
# update previous the value of download_filename_type
Channel.where(download_filename_type: nil).each do |channel|
channel.update!(download_filename_type: Channel::DEFAULT_DOWNLOAD_FILENAME_TYPE)
end
end
end
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"
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
4 changes: 3 additions & 1 deletion spec/swagger_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
bundle_id: { type: :string, example: '*' },
git_url: { type: :string, example: 'https://github.com/tryzealot/zealot' },
has_password: { type: :boolean, example: false },
download_filename_type: { type: :string, example: 'original' },
}
},
Release: {
Expand Down Expand Up @@ -336,7 +337,8 @@
slug: { type: :string, description: I18n.t('api.definitions.channel_options.properties.slug') },
bundle_id: { type: :string, description: I18n.t('api.definitions.channel_options.properties.bundle_id') },
git_url: { type: :string, description: I18n.t('api.definitions.channel_options.properties.git_url') },
password: { type: :string, description: I18n.t('api.definitions.channel_options.properties.password') }
password: { type: :string, description: I18n.t('api.definitions.channel_options.properties.password') },
download_filename_type: { type: :string, enum: Channel.download_filename_types.keys, description: I18n.t('api.definitions.channel_options.properties.download_filename_type') }
}
},
ReleaseOptions: {
Expand Down
15 changes: 14 additions & 1 deletion swagger/v1/swagger_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2318,6 +2318,10 @@
"has_password": {
"type": "boolean",
"example": false
},
"download_filename_type": {
"type": "string",
"example": "original"
}
}
},
Expand Down Expand Up @@ -2922,7 +2926,8 @@
"type": "object",
"required": [
"name",
"device_type"
"device_type",
"download_filename_type"
],
"properties": {
"name": {
Expand Down Expand Up @@ -2956,6 +2961,14 @@
"password": {
"type": "string",
"description": "Enable password visit"
},
"download_filename_type": {
"type": "string",
"enum": [
"system",
"original"
],
"description": "Download filename type"
}
}
},
Expand Down
15 changes: 14 additions & 1 deletion swagger/v1/swagger_zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2318,6 +2318,10 @@
"has_password": {
"type": "boolean",
"example": false
},
"download_filename_type": {
"type": "string",
"example": "original"
}
}
},
Expand Down Expand Up @@ -2922,7 +2926,8 @@
"type": "object",
"required": [
"name",
"device_type"
"device_type",
"download_filename_type"
],
"properties": {
"name": {
Expand Down Expand Up @@ -2956,6 +2961,14 @@
"password": {
"type": "string",
"description": "密码访问"
},
"download_filename_type": {
"type": "string",
"enum": [
"system",
"original"
],
"description": "下载文件文件名的生成规则"
}
}
},
Expand Down