Require specifying PUT/POST type on /:slug
This commit is contained in:
parent
7dbe9192cd
commit
f7a2603e7f
@ -6,12 +6,14 @@ token=$(cat $HOME/.ily_token)
|
||||
if test -z "$2"; then
|
||||
curl -X POST -H 'Accept: text/plain' \
|
||||
-H "Authorization: $token" \
|
||||
-F 'type=file' \
|
||||
-F 'upload=@'$local_file \
|
||||
-F 'ttl=2592000' \
|
||||
https://ily.li/
|
||||
else
|
||||
curl -X PUT -H 'Accept: text/plain' \
|
||||
-H "Authorization: $token" \
|
||||
-F 'type=file' \
|
||||
-F 'upload=@'$local_file \
|
||||
-F 'ttl=2592000' \
|
||||
"https://ily.li/$2"
|
||||
|
@ -86,11 +86,14 @@ export default class FileController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
protected async postFile(req: Request, res: Response): Promise<void> {
|
||||
protected async postFile(req: Request, res: Response, next: NextFunction): Promise<void> {
|
||||
if (req.body.type !== 'file') return next();
|
||||
|
||||
await this.handleFileUpload(req.body.slug || await this.generateSlug(10), req, res);
|
||||
}
|
||||
|
||||
protected async putFile(req: Request, res: Response): Promise<void> {
|
||||
protected async putFile(req: Request, res: Response, next: NextFunction): Promise<void> {
|
||||
if (req.body.type !== 'file') return next();
|
||||
const slug = req.params.slug;
|
||||
if (!slug) throw new BadRequestError('Cannot put without a slug.', 'Either provide a slug or use POST method instead.', req.url);
|
||||
|
||||
|
@ -15,7 +15,7 @@ export default class FileModel extends Model {
|
||||
}
|
||||
|
||||
public static async paginateForUser(req: Request, perPage: number, user_id: number): Promise<FileModel[]> {
|
||||
return await this.paginate<FileModel>(req, perPage, this.select().where('user_id', user_id));
|
||||
return await this.paginate(req, perPage, this.select().where('user_id', user_id));
|
||||
}
|
||||
|
||||
public readonly user_id!: number;
|
||||
|
@ -100,14 +100,17 @@
|
||||
<p>Example with curl:</p>
|
||||
<pre>curl -X POST -H 'Accept: application/json' \
|
||||
-H "Authorization: very_secret_and_personal_token" \
|
||||
-F 'type=file' \
|
||||
-F 'upload=@path/to/local/file' \
|
||||
https://ily.li/</pre>
|
||||
<pre>curl -X PUT -H 'Accept: application/json' \
|
||||
-H "Authorization: very_secret_and_personal_token" \
|
||||
-F 'type=file' \
|
||||
-F 'upload=@path/to/local/file' \
|
||||
https://ily.li/my_very_important_file.png</pre>
|
||||
<pre>curl -X POST -H 'Accept: application/json' \
|
||||
-H "Authorization: very_secret_and_personal_token" \
|
||||
-F 'type=file' \
|
||||
-F 'upload=@path/to/local/file' \
|
||||
-F 'ttl=30' \
|
||||
https://ily.li/</pre>
|
||||
|
Loading…
Reference in New Issue
Block a user