-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
185 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Zhiyi\Plus\Admin\Controllers\FileStorage; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Response; | ||
use function Zhiyi\Plus\setting; | ||
use Illuminate\Http\JsonResponse; | ||
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; | ||
|
||
class PublicChannel | ||
{ | ||
/** | ||
* Get public channel settings. | ||
* @return \Illuminate\Http\JsonResponse | ||
*/ | ||
public function show(): JsonResponse | ||
{ | ||
$configure = setting('file-storage', 'channels.public', []); | ||
$result = [ | ||
'filesystem' => $configure['filesystem'] ?? '', | ||
]; | ||
|
||
return new JsonResponse($result, Response::HTTP_OK); | ||
} | ||
|
||
/** | ||
* Update public channel settings. | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function update(Request $request): Response | ||
{ | ||
$filesystem = $request->input('filesystem'); | ||
if (! in_array($filesystem, ['local', 'AliyunOSS'])) { | ||
throw new UnprocessableEntityHttpException('选择的文件系统不受支持'); | ||
} | ||
|
||
$setting = setting('file-storage'); | ||
$setting->set('channels.public', [ | ||
'filesystem' => $filesystem, | ||
]); | ||
|
||
return new Response('', Response::HTTP_NO_CONTENT); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
resources/assets/admin/pages/file-storage/channels-component/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './wrap'; |
102 changes: 102 additions & 0 deletions
102
resources/assets/admin/pages/file-storage/channels-component/public.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<template> | ||
<div class="panel panel-default"> | ||
<div class="panel-heading">公开频道</div> | ||
<div class="panel-body"> | ||
|
||
<div class="alert alert-warning"> | ||
公开频道关键词为 <code>public</code>,公开频道中 | ||
所存储的文件均为公开免费文件!主要适用场景为<code>用户头像</code>、<code>背景图片</code>以及<code>系统文件</code> | ||
等场景。 | ||
</div> | ||
|
||
<sb-ui-loading v-if="loading" /> | ||
|
||
<div class="form-horizontal" v-else> | ||
|
||
<!-- 选择文件系统 --> | ||
<div class="form-group"> | ||
<label class="col-sm-2 control-label">文件系统</label> | ||
<div class="col-sm-3"> | ||
<select class="form-control" v-model="filesystem"> | ||
<option value="" disabled>-- 请选择文件系统 --</option> | ||
<option | ||
v-for="filesystem in filesystems" | ||
:key="filesystem.value" | ||
:value="filesystem.value" | ||
> | ||
{{ filesystem.name }} | ||
</option> | ||
</select> | ||
</div> | ||
<div class="col-sm-7 help-block"> | ||
请选择频道中所使用的文件系统。如果没有选择,将使用<code>默认文件系统</code>。 | ||
</div> | ||
</div> | ||
|
||
<!-- 提交按钮 --> | ||
<div class="form-group"> | ||
<div class="col-sm-10 col-sm-offset-2"> | ||
<ui-button type="button" class="btn btn-primary" @click="submitHandler" /> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import request, { createRequestURI } from '../../../util/request'; | ||
export default { | ||
props: { | ||
filesystems: { | ||
required: true, | ||
type: Array | ||
} | ||
}, | ||
data: () => ({ | ||
filesystem: '', | ||
loading: true | ||
}), | ||
created() { | ||
this.loading = true; | ||
request.get( | ||
createRequestURI('file-storage/channels/public'), | ||
{ | ||
validateStatus: status => status === 200 | ||
} | ||
) | ||
.then(({ data: { filesystem } }) => { | ||
this.filesystem = filesystem; | ||
this.loading = false; | ||
}) | ||
.catch(({ response: { data: message = "获取默认公开频道设置失败,请检查网络或者刷新页面重试" } }) => { | ||
this.$store.dispatch("alert-open", { type: "danger", message }); | ||
}); | ||
}, | ||
methods: { | ||
submitHandler({ stopProcessing }) { | ||
request.patch( | ||
createRequestURI('file-storage/channels/public'), | ||
{ | ||
filesystem: this.filesystem | ||
}, | ||
{ | ||
validateStatus: status => status === 204, | ||
} | ||
) | ||
.then(() => { | ||
this.$store.dispatch("alert-open", { | ||
type: "success", | ||
message: "更新成功!" | ||
}); | ||
}) | ||
.catch(({ response: { data: message = "提交失败!" } }) => { | ||
this.$store.dispatch("alert-open", { type: "danger", message }); | ||
}) | ||
.finally(stopProcessing); | ||
} | ||
} | ||
} | ||
</script> | ||
|
21 changes: 21 additions & 0 deletions
21
resources/assets/admin/pages/file-storage/channels-component/wrap.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<template> | ||
<div class="container-fluid"> | ||
<public-channel-panel :filesystems="filesystems" /> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import PublicChannelPanel from './public'; | ||
export default { | ||
components: { | ||
PublicChannelPanel, | ||
}, | ||
data: () => ({ | ||
filesystems: [ | ||
{ value: 'local', name: '本地存储' }, | ||
{ value: 'AliyunOSS', name: '阿里云 OSS' }, | ||
] | ||
}) | ||
} | ||
</script> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { default as WrapComponent } from './wrap-component'; | ||
export { default as HomeComponent } from './home-component'; | ||
export { default as FilesystemsComponent } from './filesystems-component'; | ||
export { default as ChannelsComponent } from './channels-component'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters