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: add resource test case #39

Merged
merged 5 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@
},
"dependencies": {
"axios": "^0.22.0",
"jsonwebtoken": "^8.5.1"
"form-data": "^4.0.0",
"jsonwebtoken": "^8.5.1",
"node-fetch": "^3.3.2"
}
}
10 changes: 10 additions & 0 deletions src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

import axios, { AxiosInstance, AxiosRequestConfig } from 'axios'
import * as FormData from 'form-data'

export default class Request {
private client: AxiosInstance
Expand All @@ -31,4 +32,13 @@ export default class Request {
post(url: string, data: any, config?: AxiosRequestConfig<any>) {
return this.client.post(url, data, config)
}

postFile(url: string, postFile: any, config?: AxiosRequestConfig<any>) {
const formData = new FormData()
formData.append('file', postFile)
return this.client.post(url, formData, {
params: config?.params,
headers: formData.getHeaders(),
})
}
}
59 changes: 45 additions & 14 deletions src/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@ import Request from './request'
export interface Resource {
owner: string
name: string
createdTime: string

user: string
provider: string
application: string
tag: string
parent: string
fileName: string
fileType: string
fileFormat: string
fileSize: number
url: string
description: string
createdTime?: string

user?: string
provider?: string
application?: string
tag?: string
parent?: string
fileName?: string
fileType?: string
fileFormat?: string
fileSize?: number
url?: string
description?: string
fullFilePath?: string
}

export class ResourceSDK {
Expand All @@ -43,6 +44,24 @@ export class ResourceSDK {
this.request = request
}

public async uploadResource(resource: Resource, psotFile: any) {
if (!this.request) {
throw new Error('request init failed')
}

const url = `/upload-resource`
return (await this.request.postFile(url, psotFile, {
params: {
owner: this.config.orgName,
user: resource.owner,
application: this.config.appName,
tag: resource.name,
parent: resource.parent,
fullFilePath: resource.fullFilePath,
},
})) as unknown as Promise<AxiosResponse<Record<string, unknown>>>
}

public async getResources(
owner: string,
user: string,
Expand Down Expand Up @@ -102,6 +121,18 @@ export class ResourceSDK {
}

public async deleteResource(resource: Resource) {
return this.modifyResource('delete-resource', resource)
if (!this.request) {
throw new Error('request init failed')
}

const url = `/delete-resource`
const post = {
owner: resource.owner,
name: resource.name,
}
return (await this.request.post(
url,
JSON.stringify(post),
)) as unknown as Promise<AxiosResponse<Record<string, unknown>>>
}
}
4 changes: 4 additions & 0 deletions src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,10 @@ export class SDK {
return await this.resourceSDK.deleteResource(resource)
}

public async uploadResource(resource: Resource, file: any) {
return await this.resourceSDK.uploadResource(resource, file)
}

public async getRoles() {
return await this.roleSDK.getRoles()
}
Expand Down
1 change: 1 addition & 0 deletions test/public/casbinTest.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading