-
-
Notifications
You must be signed in to change notification settings - Fork 685
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app-console): replace bucket fs api with oss
- Loading branch information
Showing
2 changed files
with
128 additions
and
16 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,104 @@ | ||
|
||
import store from '@/store' | ||
import { assert } from '@/utils/assert' | ||
import request from '@/utils/request' | ||
|
||
/** | ||
* Get bucket list | ||
* @returns | ||
*/ | ||
export async function getBuckets() { | ||
const appid = store.state.app.appid | ||
const res = await request({ | ||
url: `/apps/${appid}/oss/buckets`, | ||
method: 'get' | ||
}) | ||
|
||
assert(res.code === 0, 'get file buckets got error', res) | ||
return res | ||
} | ||
|
||
/** | ||
* Get a bucket & tokens | ||
* @returns | ||
*/ | ||
export async function getBucket(bucketName) { | ||
const appid = store.state.app.appid | ||
const res = await request({ | ||
url: `/apps/${appid}/oss/buckets/${bucketName}`, | ||
method: 'get' | ||
}) | ||
|
||
assert(res.code === 0, 'get bucket got error', res) | ||
return res | ||
} | ||
|
||
/** | ||
* Create a bucket | ||
* @param {string} bucketName | ||
* @param {number} mode | ||
* @returns {Promise<any[]>} | ||
*/ | ||
export async function createBucket(bucketName, mode) { | ||
const appid = store.state.app.appid | ||
const res = await request({ | ||
url: `/apps/${appid}/oss/buckets`, | ||
method: 'post', | ||
data: { | ||
bucket: bucketName, | ||
mode | ||
} | ||
}) | ||
|
||
assert(res.code === 0, 'create bucket got error', res) | ||
return res | ||
} | ||
|
||
/** | ||
* Update a bucket | ||
* @param {string} bucketName | ||
* @param {number} mode | ||
* @returns {Promise<any[]>} | ||
*/ | ||
export async function updateBucket(bucketName, mode) { | ||
const appid = store.state.app.appid | ||
const res = await request({ | ||
url: `/apps/${appid}/oss/buckets/${bucketName}`, | ||
method: 'put', | ||
data: { | ||
mode | ||
} | ||
}) | ||
|
||
assert(res.code === 0, 'update bucket got error', res) | ||
return res | ||
} | ||
|
||
/** | ||
* Delete a bucket | ||
* @param {string} bucketName | ||
* @returns | ||
*/ | ||
export async function deleteBucket(bucketName) { | ||
const appid = store.state.app.appid | ||
const res = await request({ | ||
url: `/apps/${appid}/oss/buckets/${bucketName}`, | ||
method: 'delete' | ||
}) | ||
|
||
assert(res.code === 0, 'delete bucket got error', res) | ||
return res | ||
} | ||
|
||
/** | ||
* 获取当前应用的指定文件桶的服务地址 | ||
* @param {*} bucket | ||
* @returns | ||
*/ | ||
export function getBucketUrl(bucket) { | ||
const appid = store.state.app.appid | ||
const domain = store.state.app.storage_deploy_host | ||
const schema = store.state.app.storage_deploy_url_schema || 'http' | ||
const url = `${schema}://${appid}-${bucket}.${domain}` | ||
return url | ||
} |
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