Skip to content

Commit db6f7dd

Browse files
Wojciech KrysiakWojciech Krysiak
authored andcommitted
docs: improve documentation
1 parent df3b060 commit db6f7dd

File tree

2 files changed

+62
-15
lines changed

2 files changed

+62
-15
lines changed

src/features/upload-file/property-custom.type.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { MimeType } from './mime-types.type'
22

33
/**
4-
* @private
5-
*
64
* Custom ({@link PropertyOptions#custom}) properties passed down to the component.
5+
* @private
76
*/
87
type PropertyCustom = {
98
filePathProperty: string,
Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,55 @@
1+
/* eslint-disable @typescript-eslint/ban-ts-comment */
12
/* eslint-disable class-methods-use-this */
2-
/* eslint-disable @typescript-eslint/no-unused-vars */
33

44
import { UploadedFile } from 'admin-bro'
55

66
/**
77
* Abstract class which is a base for every @admin-bro/upload Adapter.
88
*
99
* In order to implement your own - you have to override all of its methods.
10-
* Next, you can pass it with: {@link UploadOptions#provider}
10+
* Next, you can pass it with: {@link UploadOptions.provider}
11+
*
12+
* ### Extending {@link BaseProvider}
13+
*
14+
* ```
15+
* const { BaseProvider } = require('@admin-bro/upload')
16+
*
17+
* class MyProvider extends BaseProvider {
18+
* constructor() {
19+
* // you have to pass bucket name to the constructor
20+
* super('bucketName')
21+
* }
22+
*
23+
* public async upload() {
24+
* console.log('uploaded')
25+
* return true
26+
* }
27+
*
28+
* public async delete() {
29+
* console.log('deleted')
30+
* return true
31+
* }
32+
*
33+
* public async path() {
34+
* return '/fle-url'
35+
* }
36+
* }
37+
*
38+
* const options = {
39+
* resources: [
40+
* resource: YourResource,
41+
* features: [uploadFeature({
42+
* provider: new MyProvider(),
43+
* properties: { ... },
44+
* })],
45+
* ]
46+
* }
47+
* ```
48+
*
1149
* @memberof module:@admin-bro/upload
1250
* @alias BaseProvider
51+
* @hide
52+
* @private
1353
*/
1454
abstract class BaseProvider {
1555
/**
@@ -26,8 +66,7 @@ abstract class BaseProvider {
2666

2767
/**
2868
*
29-
* @param bucket place where files should be stored
30-
* @param options adapter options
69+
* @param {string }bucket place where files should be stored
3170
*/
3271
constructor(bucket: string) {
3372
this.name = 'BaseAdapter'
@@ -37,28 +76,37 @@ abstract class BaseProvider {
3776
/**
3877
* Uploads file to given bucket
3978
*
40-
* @param tmpFile buffer holding file to upload
41-
* @param key file path
79+
* @param {UploadedFile} file uploaded by AdminBro file
80+
* @param {string} key file path
81+
* @abstract
4282
*/
43-
public abstract async upload (file: UploadedFile, key: string): Promise<any>
83+
public async upload(file: UploadedFile, key: string): Promise<any> {
84+
throw new Error('you have to implement `BaseProvider#upload` method')
85+
}
4486

4587
/**
4688
* Deletes given file
4789
*
48-
* @param key file path
49-
* @param bucket where file should be uploaded
90+
* @param {string} key file path
91+
* @param {string} bucket where file should be uploaded
92+
* @abstract
5093
*/
51-
public abstract async delete (key: string, bucket: string): Promise<any>
94+
public async delete(key: string, bucket: string): Promise<any> {
95+
throw new Error('you have to implement `BaseProvider#delete` method')
96+
}
5297

5398
/**
5499
* Returns path for the file from where it can be downloaded. It is dynamic in case of
55100
* time based paths: i.e. link valid in the next 24h
56101
*
57-
* @param key file path
58-
* @param bucket where file should be put
102+
* @param {string} key file path
103+
* @param {string} bucket where file should be put
59104
* @async
105+
* @abstract
60106
*/
61-
public abstract path (key: string, bucket: string): Promise<string> | string
107+
public path(key: string, bucket: string): Promise<string> | string {
108+
throw new Error('you have to implement `BaseProvider#path` method')
109+
}
62110
}
63111

64112
export default BaseProvider

0 commit comments

Comments
 (0)