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

feat: urlStyle #84

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ public interface OssConstant {
*/
List<Long> SYSTEM_DATA_IDS = Arrays.asList(1L, 2L, 3L, 4L);

/**
* 云服务商
*/
String[] CLOUD_SERVICE = new String[]{"aliyun", "qcloud", "qiniu", "obs"};

/**
* https 状态
*/
String IS_HTTPS = "Y";

/**
* 启用s3路径访问风格
*/
String PATH_STYLE_ACCESS_ENABLED = "1";
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
import java.util.Date;

/**
* S3 存储协议 所有兼容S3协议的云厂商均支持
* 阿里云 腾讯云 七牛云 minio
* S3 存储协议 所有兼容S3协议的云存储服务均支持
*
* @author Lion Li
*/
Expand Down Expand Up @@ -66,22 +65,19 @@ public OssClient(String configKey, OssProperties ossProperties) {
.withEndpointConfiguration(endpointConfig)
.withClientConfiguration(clientConfig)
.withCredentials(credentialsProvider)
.withPathStyleAccessEnabled(OssConstant.PATH_STYLE_ACCESS_ENABLED.equals(properties.getUrlStyle()))
.disableChunkedEncoding();
if (!StringUtils.containsAny(properties.getEndpoint(), OssConstant.CLOUD_SERVICE)) {
// minio 使用https限制使用域名访问 需要此配置 站点填域名
build.enablePathStyleAccess();
}
this.client = build.build();

if (Boolean.TRUE.equals(ossProperties.getCreateBucket())) {
createBucket();
}
} catch (OssException e) {
throw e;
} catch (Exception e) {
if (e instanceof OssException) {
throw e;
}
throw new OssException("配置错误! 请检查系统配置:[" + e.getMessage() + "]");
}

}

public void createBucket() {
Expand Down Expand Up @@ -175,19 +171,21 @@ public InputStream getObjectContent(String path) {
public String getUrl() {
String domain = properties.getDomain();
String endpoint = properties.getEndpoint();
String header = OssConstant.IS_HTTPS.equals(properties.getIsHttps()) ? "https://" : "http://";
// 云服务商直接返回
if (StringUtils.containsAny(endpoint, OssConstant.CLOUD_SERVICE)) {
if (StringUtils.isNotBlank(domain)) {
return header + domain;
String protocol = OssConstant.IS_HTTPS.equals(properties.getIsHttps()) ? "https://" : "http://";
boolean pathStyleAccessEnabled = OssConstant.PATH_STYLE_ACCESS_ENABLED.equals(properties.getUrlStyle());
boolean customDomainIsBlank = StringUtils.isBlank(domain);
// 路径风格访问
if (pathStyleAccessEnabled) {
if (customDomainIsBlank) {
return protocol + endpoint + "/" + properties.getBucketName();
}
return header + properties.getBucketName() + "." + endpoint;
return protocol + domain + "/" + properties.getBucketName();
}
// minio 单独处理
if (StringUtils.isNotBlank(domain)) {
return header + domain + "/" + properties.getBucketName();
// 虚拟主机域名风格访问
if (customDomainIsBlank) {
return protocol + properties.getBucketName() + "." + endpoint;
}
return header + endpoint + "/" + properties.getBucketName();
return protocol + domain;
}

public String getPath(String prefix, String suffix) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,11 @@ public class OssProperties {
*/
private Boolean createBucket;

/**
* url风格(0=虚拟托管风格,1=路径风格)
*
* @see https://docs.aws.amazon.com/zh_cn/AmazonS3/latest/userguide/VirtualHosting.html
*/
private String urlStyle;

}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ public class SysOssConfigBo extends BaseEntity {
*/
private String domain;

/**
* URL风格(0=虚拟托管风格,1=路径风格)
*
* @see https://docs.aws.amazon.com/zh_cn/AmazonS3/latest/userguide/VirtualHosting.html
*/
private String urlStyle = "0";

/**
* 是否https(Y=是,N=否)
*/
Expand Down
7 changes: 7 additions & 0 deletions ruoyi-ui/src/api/system/model/ossConfigModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ export interface SysOssConfigVo {
prefix?: string;
/** 访问站点 */
endpoint?: string;
/** 访问站点url风格
*
* 0:虚拟主机风格(virtualHostStyle)
*
* 1:路径风格(pathStyle)
*/
urlStyle?: '0' | '1';
/** 自定义域名 */
domain?: string;
/** 是否https(Y=是,N=否) */
Expand Down
117 changes: 102 additions & 15 deletions ruoyi-ui/src/pages/system/ossConfig/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@
<template #accessPolicy="{ row }">
<dict-tag :options="accessPolicyOptions" :value="row.accessPolicy" />
</template>
<template #urlStyle="{ row }">
<dict-tag :options="oss_url_style" :value="row.urlStyle" />
</template>
<template #status="{ row }">
<t-switch
v-model="row.status"
Expand Down Expand Up @@ -152,39 +155,112 @@
<t-loading :loading="buttonLoading" size="small">
<t-form ref="ossConfigRef" :data="form" :rules="rules" label-width="calc(6em + 41px)" @submit="submitForm">
<t-form-item label="配置key" name="configKey">
<t-input v-model="form.configKey" placeholder="请输入配置key" />
</t-form-item>
<t-form-item label="访问站点" name="endpoint">
<t-input v-model="form.endpoint" placeholder="请输入访问站点" />
<t-input v-model.trim="form.configKey" placeholder="请输入配置key" />
</t-form-item>
<t-form-item label="自定义域名" name="domain">
<t-input v-model="form.domain" placeholder="请输入自定义域名" />
<t-form-item name="endpoint">
<template #label>
<t-tooltip placement="top-start">
<help-circle-icon size="small" /> 访问站点
<template #content> 对应S3 SDK的endpoint参数 </template>
</t-tooltip>
</template>
<t-input v-model.trim="form.endpoint" placeholder="请输入访问站点" />
</t-form-item>
<t-form-item label="accessKey" name="accessKey">
<t-input v-model="form.accessKey" placeholder="请输入accessKey" />
<t-input v-model.trim="form.accessKey" placeholder="请输入accessKey" />
</t-form-item>
<t-form-item label="secretKey" name="secretKey">
<t-input v-model="form.secretKey" placeholder="请输入秘钥" type="password" />
<t-input v-model.trim="form.secretKey" placeholder="请输入秘钥" type="password" />
</t-form-item>
<t-form-item label="桶名称" name="bucketName">
<t-input v-model="form.bucketName" placeholder="请输入桶名称" />
<t-form-item name="bucketName">
<template #label>
<t-tooltip placement="top-start">
<help-circle-icon size="small" /> 存储桶名称
<template #content> 对应S3 SDK的bucketName参数 </template>
</t-tooltip>
</template>
<t-input v-model.trim="form.bucketName" placeholder="请输入桶名称" />
</t-form-item>
<t-form-item name="urlStyle">
<template #label>
<t-popup :overlay-style="{ width: '300px' }">
<template #content>
更多细节信息参考
<t-link
theme="primary"
href="https://docs.aws.amazon.com/zh_cn/AmazonS3/latest/userguide/VirtualHosting.html#path-style-access"
target="_blank"
rel="noopener noreferrer"
>
S3官方文档(存储桶的虚拟托管)
<template #suffix-icon>
<jump-icon />
</template>
</t-link>
</template>
<help-circle-icon size="small" /> URL风格
</t-popup>
</template>
<t-radio-group v-model="form.urlStyle">
<t-radio v-for="dict in oss_url_style" :key="dict.value" :value="dict.value">{{ dict.label }}</t-radio>
</t-radio-group>
<template #help>
<template v-if="form.urlStyle === '0'">
<help-circle-icon size="small" />
阿里云、腾讯云、华为云等云服务厂商提供的存储服务请使用此风格
</template>
<template v-if="form.urlStyle === '1'">
<help-circle-icon size="small" />
minio、ceph等自建S3服务如无特殊配置请使用此风格
</template>
</template>
</t-form-item>
<t-form-item label="创建桶" name="createBucket">
<t-form-item name="createBucket">
<template #label>
<t-tooltip placement="top-start">
<help-circle-icon size="small" /> 创建存储桶
<template #content> 启用时若存储桶不存在则自动创建,提供的accessKey需要有相关权限 </template>
</t-tooltip>
</template>
<t-switch v-model="form.createBucket" :custom-value="[1, 0]" />
</t-form-item>
<t-form-item label="前缀" name="prefix">
<t-input v-model="form.prefix" placeholder="请输入前缀" />
<t-input v-model.trim="form.prefix" placeholder="请输入前缀" />
</t-form-item>
<t-form-item label="是否HTTPS">
<t-radio-group v-model="form.isHttps">
<t-radio v-for="dict in sys_yes_no" :key="dict.value" :value="dict.value">{{ dict.label }}</t-radio>
</t-radio-group>
</t-form-item>
<t-form-item label="自定义域名" name="domain">
<t-input v-model.trim="form.domain" placeholder="请输入自定义域名" />
</t-form-item>
<t-form-item label="URL访问示例">
<span>
<template v-if="form.isHttps === 'Y'">https://</template>
<template v-else-if="form.isHttps === 'N'">http://</template>
<template v-if="form.urlStyle === '1'">
<template v-if="form.domain">{{ form.domain }}/{{ form.bucketName }}</template>
<template v-else>{{ form.endpoint }}/{{ form.bucketName }}</template>
</template>
<template v-else-if="form.urlStyle === '0'">
<template v-if="form.domain">{{ form.domain }}</template>
<template v-else>{{ form.bucketName }}.{{ form.endpoint }}</template>
</template>
<template v-if="form.prefix">/{{ form.prefix }}</template>
</span>
</t-form-item>
<t-form-item label="桶权限类型">
<t-radio-group v-model="form.accessPolicy" :options="accessPolicyOptions" />
</t-form-item>
<t-form-item label="域" name="region">
<t-input v-model="form.region" placeholder="请输入域" />
<t-form-item name="region">
<template #label>
<t-tooltip placement="top-start">
<help-circle-icon size="small" /> 域
<template #content> 对应S3 SDK的region参数 </template>
</t-tooltip>
</template>
<t-input v-model.trim="form.region" placeholder="请输入域" />
</t-form-item>
<t-form-item label="备注" name="remark">
<t-textarea v-model="form.remark" placeholder="请输入备注" />
Expand Down Expand Up @@ -214,6 +290,9 @@
<t-descriptions-item label="是否https">
<dict-tag :options="sys_yes_no" :value="form.isHttps" />
</t-descriptions-item>
<t-descriptions-item label="URL风格">
<dict-tag :options="oss_url_style" :value="form.urlStyle" />
</t-descriptions-item>
<t-descriptions-item label="域">{{ form.region }}</t-descriptions-item>
<t-descriptions-item label="桶权限类型">
<dict-tag :options="accessPolicyOptions" :value="form.accessPolicy" />
Expand All @@ -240,6 +319,8 @@ import {
BrowseIcon,
DeleteIcon,
EditIcon,
HelpCircleIcon,
JumpIcon,
RefreshIcon,
SearchIcon,
SettingIcon,
Expand All @@ -261,7 +342,11 @@ import type { DictModel } from '@/utils/dict';
import { handleChangeStatus } from '@/utils/ruoyi';

const { proxy } = getCurrentInstance();
const { sys_yes_no, sys_normal_disable } = proxy.useDict('sys_yes_no', 'sys_normal_disable');
const { sys_yes_no, sys_normal_disable, oss_url_style } = proxy.useDict(
'sys_yes_no',
'sys_normal_disable',
'oss_url_style',
);

const openView = ref(false);
const openViewLoading = ref(false);
Expand Down Expand Up @@ -292,6 +377,7 @@ const columns = ref<Array<PrimaryTableCol>>([
{ title: `自定义域名`, colKey: 'domain', align: 'center', ellipsis: true },
{ title: `桶名称`, colKey: 'bucketName', align: 'center' },
{ title: `前缀`, colKey: 'prefix', align: 'center' },
{ title: `URL风格`, colKey: 'urlStyle', align: 'center' },
{ title: `域`, colKey: 'region', align: 'center' },
{ title: `桶权限类型`, colKey: 'accessPolicy', align: 'center' },
{ title: `是否默认`, colKey: 'status', align: 'center' },
Expand Down Expand Up @@ -327,6 +413,7 @@ const rules = ref<Record<string, Array<FormRule>>>({
trigger: 'blur',
},
],
urlStyle: [{ required: true, message: '请选择URL风格' }],
endpoint: [
{ required: true, message: 'endpoint不能为空' },
{
Expand Down
2 changes: 1 addition & 1 deletion ruoyi-ui/src/types/custom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {
selectDictLabels,
} from '@/utils/ruoyi';

declare module '@vue/runtime-core' {
declare module 'vue' {
interface ComponentCustomProperties {
useDict: typeof useDict;
getConfigKey: typeof getConfigKey;
Expand Down
3 changes: 1 addition & 2 deletions ruoyi-ui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
"src/types/**/*.d.ts",
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"node_modules/tdesign-vue-next/global.d.ts"
"src/**/*.vue"
],
"compileOnSave": false
}
15 changes: 10 additions & 5 deletions script/sql/oracle/oracle_ry_vue_1.X.sql
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,7 @@ insert into sys_dict_type values(14, '000000', '消息模板类型', 'sys_messag
insert into sys_dict_type values(15, '000000', '授权类型', 'sys_grant_type', 103, 1, sysdate, null, null, '认证授权类型');
insert into sys_dict_type values(16, '000000', '设备类型', 'sys_device_type', 103, 1, sysdate, null, null, '客户端设备类型');
insert into sys_dict_type values(17, '000000', '敏感词类别', 'sensitive_words_category', 103, 1, sysdate, 1, sysdate, null);
insert into sys_dict_type values(18, '000000', 'OSS的URL风格', 'oss_url_style', 103, 1, sysdate, 1, sysdate, 'https://docs.aws.amazon.com/zh_cn/AmazonS3/latest/userguide/VirtualHosting.html#VirtualHostingControl');


-- ----------------------------
Expand Down Expand Up @@ -987,6 +988,8 @@ insert into sys_dict_data values(59, '000000', 12, '鼎众短信', 'DING_ZHONG',
insert into sys_dict_data values(60, '000000', 13, '联麓短信', 'LIAN_LU', 'sys_message_supplier_type', null, 'primary', '', 'N', 103, 1, sysdate, 1, sysdate, null);
insert into sys_dict_data values(61, '000000', 14, '七牛云短信', 'QI_NIU', 'sys_message_supplier_type', null, 'primary', null, 'N', 103, 1, sysdate, 1, sysdate, null);
insert into sys_dict_data values(70, '000000', 99, '其他', 'other', 'sensitive_words_category', null, 'primary', null, 'N', 103, 1, sysdate, 1, sysdate, null);
insert into sys_dict_data values(71, '000000', 1, '虚拟托管风格', '0', 'oss_url_style', '', '', '', 'Y', 103, 1, sysdate, null, null, '示例:<bucket-name>.s3.region-code.amazonaws.com');
insert into sys_dict_data values(72, '000000', 2, '路径风格', '1', 'oss_url_style', '', '', '', 'N', 103, 1, sysdate, null, null, '示例:s3.region-code.amazonaws.com/<bucket-name>');


-- ----------------------------
Expand Down Expand Up @@ -1310,6 +1313,7 @@ create table sys_oss_config (
prefix varchar2(255) default '',
endpoint varchar2(255) default '',
domain varchar2(255) default '',
url_style char(1) default '0',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

缺少字段备注

is_https char(1) default 'N',
region varchar2(255) default '',
access_policy char(1) default '1' not null,
Expand All @@ -1336,6 +1340,7 @@ comment on column sys_oss_config.bucket_name is '桶名称';
comment on column sys_oss_config.prefix is '前缀';
comment on column sys_oss_config.endpoint is '访问站点';
comment on column sys_oss_config.domain is '自定义域名';
comment on column sys_oss_config.url_style is 'URL(0=虚拟托管风格,1=路径风格)';
comment on column sys_oss_config.is_https is '是否https(Y=是,N=否)';
comment on column sys_oss_config.region is '域';
comment on column sys_oss_config.access_policy is '桶权限类型(0=private 1=public 2=custom)';
Expand All @@ -1349,11 +1354,11 @@ comment on column sys_oss_config.create_time is '创建时间';
comment on column sys_oss_config.update_by is '更新者';
comment on column sys_oss_config.update_time is '更新时间';

insert into sys_oss_config values (1, '000000', 'minio', 'ruoyi', 'ruoyi123', 'ruoyi', '', '127.0.0.1:9000', '','N', '', '1', '1', 0,'', NULL, 103, 1, sysdate, 1, sysdate);
insert into sys_oss_config values (2, '000000', 'qiniu', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi', '', 's3-cn-north-1.qiniucs.com', '','N', '', '1', '0', 0,'', NULL, 103, 1, sysdate, 1, sysdate);
insert into sys_oss_config values (3, '000000', 'aliyun', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi', '', 'oss-cn-beijing.aliyuncs.com', '','N', '', '1', '0', 0,'', NULL, 103, 1, sysdate, 1, sysdate);
insert into sys_oss_config values (4, '000000', 'qcloud', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi-1250000000', '', 'cos.ap-beijing.myqcloud.com', '','N', 'ap-beijing', '1', '0', 0,'', NULL, 103, 1, sysdate, 1, sysdate);
insert into sys_oss_config values (5, '000000', 'image', 'ruoyi', 'ruoyi123', 'ruoyi', 'image', '127.0.0.1:9000', '','N', '', '1', '0', 0,'', NULL, 103, 1, sysdate, 1, sysdate);
insert into sys_oss_config values (1, '000000', 'minio', 'ruoyi', 'ruoyi123', 'ruoyi', '', '127.0.0.1:9000', '','1','N', '', '1', '1', 0,'', NULL, 103, 1, sysdate, 1, sysdate);
insert into sys_oss_config values (2, '000000', 'qiniu', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi', '', 's3-cn-north-1.qiniucs.com', '','0','N', '', '1', '0', 0,'', NULL, 103, 1, sysdate, 1, sysdate);
insert into sys_oss_config values (3, '000000', 'aliyun', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi', '', 'oss-cn-beijing.aliyuncs.com', '','0','N', '', '1', '0', 0,'', NULL, 103, 1, sysdate, 1, sysdate);
insert into sys_oss_config values (4, '000000', 'qcloud', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi-1250000000', '', 'cos.ap-beijing.myqcloud.com', '','0','N', 'ap-beijing', '1', '0', 0,'', NULL, 103, 1, sysdate, 1, sysdate);
insert into sys_oss_config values (5, '000000', 'image', 'ruoyi', 'ruoyi123', 'ruoyi', 'image', '127.0.0.1:9000', '','1','N', '', '1', '0', 0,'', NULL, 103, 1, sysdate, 1, sysdate);

-- ----------------------------
-- 系统授权表
Expand Down
Loading