Skip to content

Commit

Permalink
DeviantArt: add warning about invalid title (#366)
Browse files Browse the repository at this point in the history
* da: add warning about invalid title

* da title: allow empty

---------

Co-authored-by: leaftail1880 <[email protected]>
  • Loading branch information
leaftail1880 and leaftail1880 authored Oct 15, 2024
1 parent 5e6ec79 commit aa8f49a
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,17 @@ export class DeviantArt extends Website {
});
}

private invalidTitleMessage(title: string) {
// Taken from api error message
return `'${title}' is not an valid title. Deviation title can only contain A-Z, a-z, 0-9, space and the following characters: _$!?:.,' +-=~\`@#%^*[]()/{}\\|`;
}

private titleRegex = /^[A-Za-z0-9\s_$!?:.,'+\-=~`@#%^*\[\]()\/\{\}\\|]*$/g;

private truncateTitle(title: string) {
const newTitle = title.substring(0, this.titleLimit);
return { title: newTitle, exceedsLimit: newTitle !== title };
const isValid = this.titleRegex.test(title);
return { title: newTitle, exceedsLimit: newTitle !== title, isValid };
}

validateFileSubmission(
Expand All @@ -378,12 +386,15 @@ export class DeviantArt extends Website {
const warnings: string[] = [];
const isAutoscaling: boolean = submissionPart.data.autoScale;

const { title, exceedsLimit } = this.truncateTitle(
const { title, exceedsLimit, isValid } = this.truncateTitle(
submissionPart.data.title || defaultPart.data.title || submission.title,
);
if (exceedsLimit) {
warnings.push(`Title will be truncated to ${this.titleLimit} characters: ${title}`);
}
if (!isValid) {
problems.push(this.invalidTitleMessage(title));
}

if (submissionPart.data.folders && submissionPart.data.folders.length) {
const folders: Folder[] = _.get(
Expand Down

0 comments on commit aa8f49a

Please sign in to comment.