Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeviantArt: add warning about invalid title #366

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,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 @@ -372,12 +380,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