Skip to content

Commit a2ee10b

Browse files
authored
feat: file censor (#656)
1 parent c1f26b2 commit a2ee10b

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/file.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const cos = require('./uploader/cos');
33
const qiniu = require('./uploader/qiniu');
44
const s3 = require('./uploader/s3');
55
const AVError = require('./error');
6-
const AVRequest = require('./request')._request;
6+
const { request, _request: AVRequest } = require('./request');
77
const { tap, transformFetchOptions } = require('./utils');
88
const debug = require('debug')('leancloud:file');
99
const parseBase64 = require('./utils/parse-base64');
@@ -196,6 +196,23 @@ module.exports = function(AV) {
196196
return file;
197197
};
198198

199+
/**
200+
* Request file censor.
201+
* @since 4.13.0
202+
* @param {String} objectId
203+
* @return {Promise.<string>}
204+
*/
205+
AV.File.censor = function(objectId) {
206+
if (!AV._config.masterKey) {
207+
throw new Error('Cannot censor a file without masterKey');
208+
}
209+
return request({
210+
method: 'POST',
211+
path: `/files/${objectId}/censor`,
212+
authOptions: { useMasterKey: true },
213+
}).then(res => res.censorResult);
214+
};
215+
199216
_.extend(
200217
AV.File.prototype,
201218
/** @lends AV.File.prototype */ {
@@ -652,6 +669,18 @@ module.exports = function(AV) {
652669
_.extend(this, value);
653670
return this;
654671
},
672+
673+
/**
674+
* Request file censor
675+
* @since 4.13.0
676+
* @return {Promise.<string>}
677+
*/
678+
censor() {
679+
if (!this.id) {
680+
throw new Error('Cannot censor an unsaved file');
681+
}
682+
return AV.File.censor(this.id);
683+
},
655684
}
656685
);
657686
};

storage.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ export class ACL extends BaseObject {
150150
getWriteAccess(userId: string): boolean;
151151
}
152152

153+
export namespace File {
154+
export type CensorResult = 'rejected' | 'passed' | 'review';
155+
}
156+
153157
/**
154158
* A AV.File is a local representation of a file that is saved to the AV
155159
* cloud.
@@ -187,6 +191,7 @@ export class File extends BaseObject {
187191
constructor(name: string, data: any, type?: string);
188192
static withURL(name: string, url: string): File;
189193
static createWithoutData(objectId: string): File;
194+
static censor(objectId: string): Promise<File.CensorResult>;
190195

191196
destroy(options?: AuthOptions): Promise<void>;
192197
fetch(fetchOptions?: FetchOptions, options?: AuthOptions): Promise<this>;
@@ -205,6 +210,7 @@ export class File extends BaseObject {
205210
setUploadHeader(key: string, value: string): this;
206211
size(): any;
207212
thumbnailURL(width: number, height: number): string;
213+
censor(): Promise<File.CensorResult>;
208214
toFullJSON(): any;
209215
}
210216

0 commit comments

Comments
 (0)