Skip to content

Commit

Permalink
feat(uploader): add config 'elan.aliyun.maxKeys'
Browse files Browse the repository at this point in the history
  • Loading branch information
fangbinwei committed Jun 21, 2020
1 parent 3451fbe commit 3a0aac9
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .cz-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
}
],

scopes: [{ name: 'uploader' }, {name: 'bucketExplorer'}, { name: 'templateSubstitute' }],
scopes: [{ name: 'uploader' }, {name: 'hover'}, {name: 'bucketExplorer'}, { name: 'templateSubstitute' }],

allowTicketNumber: false,
isTicketNumberRequired: false,
Expand Down
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@
"markdownDescription": "e.g. `oss-cn-shanghai`, [check details](https://github.com/ali-sdk/ali-oss#data-regions).",
"default": ""
},
"elan.aliyun.maxKeys": {
"type": "number",
"description": "Max objects in the same level directory of bucket treeView.",
"default": 100,
"minimum": 1,
"maximum": 1000
},
"elan.uploadName": {
"type": "string",
"markdownDescription": "Object name store on OSS\n- `${fileName}`: Filename of uploaded file.\n-`${ext}`: Filename extension of uploaded file.\n- `${contentHash}`: The hash of image. By default, it's the hex digest of md5 hash. You can specify the length of the hash, e.g. `${contentHash:8}`. \n-`${activeMdFilename}`: Filename of active markdown in text editor.",
Expand Down
1 change: 1 addition & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export function deactivate(): void {}

function initializeExtensionVariables(ctx: vscode.ExtensionContext): void {
ext.context = ctx
// there are two position get oss configuration now, may redundant
ext.OSSConfiguration = getOSSConfiguration()
ctx.subscriptions.push(
vscode.workspace.onDidChangeConfiguration(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/uploader/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import vscode from 'vscode'
import OSS from 'ali-oss'
import Logger from '@/utils/log'
import { getOSSConfiguration } from '@/utils/index'
import { getOSSConfiguration, OSSConfiguration } from '@/utils/index'
import { ext } from '@/extensionVariables'

interface DeleteResponse {
Expand All @@ -11,7 +11,7 @@ interface DeleteResponse {
export default class Uploader {
private static cacheUploader: Uploader | null = null
private client: OSS
public configuration: OSS.Options
public configuration: OSSConfiguration
public expired: boolean
constructor() {
this.configuration = getOSSConfiguration()
Expand Down Expand Up @@ -60,7 +60,7 @@ export default class Uploader {
options?: OSS.RequestOptions
): Promise<OSS.ListObjectResult> {
const defaultConfig = {
'max-keys': 100,
'max-keys': this.configuration.maxKeys,
delimiter: '/'
}
query = Object.assign(defaultConfig, query)
Expand Down
14 changes: 10 additions & 4 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,24 @@ export function removeTrailingSlash(p: string): string {
return p.replace(/\/+$/, '')
}

export function getOSSConfiguration(): OSS.Options {
export interface OSSConfiguration extends OSS.Options {
maxKeys: number
}

export function getOSSConfiguration(): OSSConfiguration {
const config = vscode.workspace.getConfiguration('elan')
const aliyunConfig = config.get<OSS.Options>('aliyun', {
const aliyunConfig = config.get<OSSConfiguration>('aliyun', {
accessKeyId: '',
accessKeySecret: ''
accessKeySecret: '',
maxKeys: 100
})
return {
secure: true, // ensure protocol of callback url is https
accessKeyId: aliyunConfig.accessKeyId.trim(),
accessKeySecret: aliyunConfig.accessKeySecret.trim(),
bucket: aliyunConfig.bucket?.trim(),
region: aliyunConfig.region?.trim()
region: aliyunConfig.region?.trim(),
maxKeys: aliyunConfig.maxKeys
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/views/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ export class BucketExplorerProvider
prefix = prefix === this.uploader.configuration.bucket ? '' : prefix + '/'

const res = await this.uploader.list({
prefix,
'max-keys': 100 //TODO: need config by user, need use 'maker' when exceed 1000
prefix
})
// we should create an empty 'folder' sometimes
// this 'empty object' is the 'parent folder' of these objects
Expand Down

0 comments on commit 3a0aac9

Please sign in to comment.