Require specifying PUT/POST type on /:slug
This commit is contained in:
parent
7dbe9192cd
commit
f7a2603e7f
@ -4,15 +4,17 @@ local_file=$1
|
|||||||
token=$(cat $HOME/.ily_token)
|
token=$(cat $HOME/.ily_token)
|
||||||
|
|
||||||
if test -z "$2"; then
|
if test -z "$2"; then
|
||||||
curl -X POST -H 'Accept: text/plain' \
|
curl -X POST -H 'Accept: text/plain' \
|
||||||
-H "Authorization: $token" \
|
-H "Authorization: $token" \
|
||||||
-F 'upload=@'$local_file \
|
-F 'type=file' \
|
||||||
-F 'ttl=2592000' \
|
-F 'upload=@'$local_file \
|
||||||
https://ily.li/
|
-F 'ttl=2592000' \
|
||||||
|
https://ily.li/
|
||||||
else
|
else
|
||||||
curl -X PUT -H 'Accept: text/plain' \
|
curl -X PUT -H 'Accept: text/plain' \
|
||||||
-H "Authorization: $token" \
|
-H "Authorization: $token" \
|
||||||
-F 'upload=@'$local_file \
|
-F 'type=file' \
|
||||||
-F 'ttl=2592000' \
|
-F 'upload=@'$local_file \
|
||||||
"https://ily.li/$2"
|
-F 'ttl=2592000' \
|
||||||
|
"https://ily.li/$2"
|
||||||
fi
|
fi
|
||||||
|
@ -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);
|
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;
|
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);
|
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[]> {
|
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;
|
public readonly user_id!: number;
|
||||||
|
@ -100,14 +100,17 @@
|
|||||||
<p>Example with curl:</p>
|
<p>Example with curl:</p>
|
||||||
<pre>curl -X POST -H 'Accept: application/json' \
|
<pre>curl -X POST -H 'Accept: application/json' \
|
||||||
-H "Authorization: very_secret_and_personal_token" \
|
-H "Authorization: very_secret_and_personal_token" \
|
||||||
|
-F 'type=file' \
|
||||||
-F 'upload=@path/to/local/file' \
|
-F 'upload=@path/to/local/file' \
|
||||||
https://ily.li/</pre>
|
https://ily.li/</pre>
|
||||||
<pre>curl -X PUT -H 'Accept: application/json' \
|
<pre>curl -X PUT -H 'Accept: application/json' \
|
||||||
-H "Authorization: very_secret_and_personal_token" \
|
-H "Authorization: very_secret_and_personal_token" \
|
||||||
|
-F 'type=file' \
|
||||||
-F 'upload=@path/to/local/file' \
|
-F 'upload=@path/to/local/file' \
|
||||||
https://ily.li/my_very_important_file.png</pre>
|
https://ily.li/my_very_important_file.png</pre>
|
||||||
<pre>curl -X POST -H 'Accept: application/json' \
|
<pre>curl -X POST -H 'Accept: application/json' \
|
||||||
-H "Authorization: very_secret_and_personal_token" \
|
-H "Authorization: very_secret_and_personal_token" \
|
||||||
|
-F 'type=file' \
|
||||||
-F 'upload=@path/to/local/file' \
|
-F 'upload=@path/to/local/file' \
|
||||||
-F 'ttl=30' \
|
-F 'ttl=30' \
|
||||||
https://ily.li/</pre>
|
https://ily.li/</pre>
|
||||||
|
Loading…
Reference in New Issue
Block a user