2019-02-05 02:48:08 +00:00
|
|
|
import $ from 'cafy';
|
2021-08-19 12:55:45 +00:00
|
|
|
import { ID } from '@/misc/cafy-id';
|
2021-11-12 10:47:04 +00:00
|
|
|
import ms from 'ms';
|
2021-08-19 12:55:45 +00:00
|
|
|
import uploadFromUrl from '@/services/drive/upload-from-url';
|
|
|
|
import define from '../../../define';
|
|
|
|
import { DriveFiles } from '@/models/index';
|
|
|
|
import { publishMainStream } from '@/services/stream';
|
2021-09-29 16:44:22 +00:00
|
|
|
import { DB_MAX_IMAGE_COMMENT_LENGTH } from '@/misc/hard-limits';
|
2017-02-16 20:46:14 +00:00
|
|
|
|
2018-07-16 19:36:44 +00:00
|
|
|
export const meta = {
|
2019-02-23 02:20:58 +00:00
|
|
|
tags: ['drive'],
|
|
|
|
|
2018-07-16 19:36:44 +00:00
|
|
|
limit: {
|
|
|
|
duration: ms('1hour'),
|
2021-12-09 14:58:30 +00:00
|
|
|
max: 60,
|
2018-07-16 19:36:44 +00:00
|
|
|
},
|
|
|
|
|
2022-01-18 13:27:10 +00:00
|
|
|
requireCredential: true,
|
2018-07-16 19:36:44 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
kind: 'write:drive',
|
2018-11-01 18:32:24 +00:00
|
|
|
|
|
|
|
params: {
|
|
|
|
url: {
|
|
|
|
// TODO: Validate this url
|
|
|
|
validator: $.str,
|
|
|
|
},
|
|
|
|
|
|
|
|
folderId: {
|
2019-02-13 07:33:07 +00:00
|
|
|
validator: $.optional.nullable.type(ID),
|
2021-06-08 05:14:58 +00:00
|
|
|
default: null,
|
2018-11-01 18:32:24 +00:00
|
|
|
},
|
2018-11-07 03:12:43 +00:00
|
|
|
|
|
|
|
isSensitive: {
|
2019-02-13 07:33:07 +00:00
|
|
|
validator: $.optional.bool,
|
2018-11-07 03:12:43 +00:00
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
comment: {
|
2021-09-29 16:44:22 +00:00
|
|
|
validator: $.optional.nullable.str.max(DB_MAX_IMAGE_COMMENT_LENGTH),
|
2021-06-08 05:14:58 +00:00
|
|
|
default: null,
|
2020-10-17 11:12:00 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
marker: {
|
|
|
|
validator: $.optional.nullable.str,
|
2021-06-08 05:14:58 +00:00
|
|
|
default: null,
|
2020-10-17 11:12:00 +00:00
|
|
|
},
|
|
|
|
|
2018-11-07 03:12:43 +00:00
|
|
|
force: {
|
2019-02-13 07:33:07 +00:00
|
|
|
validator: $.optional.bool,
|
2018-11-07 03:12:43 +00:00
|
|
|
default: false,
|
2021-12-09 14:58:30 +00:00
|
|
|
},
|
|
|
|
},
|
2022-01-18 13:27:10 +00:00
|
|
|
} as const;
|
2018-07-16 19:36:44 +00:00
|
|
|
|
2022-01-02 17:12:50 +00:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2019-02-22 02:46:58 +00:00
|
|
|
export default define(meta, async (ps, user) => {
|
2020-10-17 11:12:00 +00:00
|
|
|
uploadFromUrl(ps.url, user, ps.folderId, null, ps.isSensitive, ps.force, false, ps.comment).then(file => {
|
|
|
|
DriveFiles.pack(file, { self: true }).then(packedFile => {
|
|
|
|
publishMainStream(user.id, 'urlUploadFinished', {
|
|
|
|
marker: ps.marker,
|
2021-12-09 14:58:30 +00:00
|
|
|
file: packedFile,
|
2020-10-17 11:12:00 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-02-22 02:46:58 +00:00
|
|
|
});
|