in src/components/attachments-row/attachment-actions.ts [101:148]
doUploadFile: function (
isArticle: boolean = false,
files: NormalizedAttachment[],
entity: IssueFull | Article | IssueCreate,
) {
return async (
dispatch: (arg0: any) => any,
getState: StateGetter,
getApi: ApiGetter,
) => {
const api: Api = getApi();
const attachApi: ArticlesAPI | IssueAPI = isArticle ? api.articles : api.issue;
const [error, addedAttachments]: [CustomError | null, Attachment[]] = await until(
files.map((file: NormalizedAttachment) => attachApi.attachFile(entity.id, file)),
true,
) as [CustomError | null, Attachment[]];
if (error) {
notifyError(error);
return [];
} else {
log.info(`Attachment Actions: File attached to the ${isArticle ? 'Article' : 'Issue'}`);
usage.trackEvent(
isArticle ? ANALYTICS_ARTICLE_PAGE : ANALYTICS_ISSUE_PAGE,
'Attach image success',
);
dispatch(actions.stopImageAttaching());
dispatch(actions.toggleAttachFileDialog(false));
const visibility: Visibility | undefined = files[0].visibility;
if (visibility) {
const [err, attachmentsWithVisibility]: [CustomError | null, Attachment[]] = await until(
addedAttachments.map(
(attach: Attachment) => (attachApi.updateAttachmentVisibility(
entity.id,
attach,
visibility,
hasType.articleDraft(entity)
))
),
true,
) as [CustomError | null, Attachment[]];
return err ? addedAttachments : attachmentsWithVisibility;
} else {
return addedAttachments;
}
}
};
} ,