Skip to content
Closed
Show file tree
Hide file tree
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
11 changes: 9 additions & 2 deletions bull/google-books-queue/consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ GoogleBooksQueue.process((job, done) => {
pageCount,
infoLink,
} = volumeInfo;
var isValidEnglishChar = /^[a-zA-Z0-9!@#$%^&*()_+{}\[\]:;<>,.?~\\/-\s]+$/;
const validEnglishTitle = isValidEnglishChar.test(title)
? title
: "non english characters";
const validEnglishPublisher = isValidEnglishChar.test(publisher)
? publisher
: "non english characters";
const { accessViewStatus } = accessInfo;
const bucketTitle = job.data.IAIdentifier;
const IAuri = `http://s3.us.archive.org/${bucketTitle}/${bucketTitle}.pdf`;
Expand All @@ -59,13 +66,13 @@ GoogleBooksQueue.process((job, done) => {
"X-Amz-Auto-Make-Bucket": "1",
"X-Archive-Meta-Collection": "opensource",
"X-Archive-Ignore-Preexisting-Bucket": 1,
"X-archive-meta-title": title.trim(),
"X-archive-meta-title": validEnglishTitle.trim(),
"X-archive-meta-date": publishedDate.trim(),
"X-archive-meta-language": language.trim(),
"X-archive-meta-mediatype": "texts",
"X-archive-meta-licenseurl":
"https://creativecommons.org/publicdomain/mark/1.0/",
"X-archive-meta-publisher": publisher.trim(),
"X-archive-meta-publisher": validEnglishPublisher.trim(),
"X-archive-meta-rights": accessViewStatus.trim(),
"X-archive-meta-Google-id": id,
"X-archive-meta-Identifier": `bub_gb_${id}`,
Expand Down
95 changes: 62 additions & 33 deletions components/Books.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Swal from "sweetalert2";
import { host } from "../utils/constants";
import { withSession } from "../hooks/withSession";
import { signIn } from "next-auth/react";
import ChangeIdentifier from "./ChangeIdentifier";

class Books extends React.Component {
/**
Expand All @@ -18,6 +19,7 @@ class Books extends React.Component {
show: true,
loader: false,
isDuplicate: false,
isEnglish: true,
IATitle: "",
IAIdentifier: "",
inputDisabled: false,
Expand All @@ -34,6 +36,7 @@ class Books extends React.Component {
option: event.target.value,
bookid: "",
isDuplicate: false,
isEnglish: true,
IATitle: "",
IAIdentifier: "",
inputDisabled: false,
Expand Down Expand Up @@ -95,6 +98,7 @@ class Books extends React.Component {
onResetButtonClicked = () => {
this.setState({
isDuplicate: false,
isEnglish: true,
inputDisabled: false,
IATitle: "",
IAIdentifier: "",
Expand Down Expand Up @@ -202,9 +206,11 @@ class Books extends React.Component {
this.setState({
loader: true,
isDuplicate: false,
isEnglish: true,
});

let url = "";
var isValidEnglishChar = /^[a-zA-Z0-9!@#$%^&*()_+{}\[\]:;<>,.?~\\/-\s]+$/;
switch (this.state.option) {
case "gb":
url = `${host}/check?bookid=${this.state.bookid}&option=${
Expand All @@ -223,6 +229,12 @@ class Books extends React.Component {
IATitle: response.titleInIA,
inputDisabled: true,
});
} else if (!isValidEnglishChar.test(response.IAIdentifier)) {
this.setState({
isEnglish: false,
IATitle: response.IAIdentifier,
inputDisabled: true,
});
} else {
if (response.error) {
Swal("Error!", response.message, "error");
Expand Down Expand Up @@ -314,6 +326,12 @@ class Books extends React.Component {
IATitle: response.titleInIA,
inputDisabled: true,
});
} else if (!isValidEnglishChar.test(response.IAIdentifier)) {
this.setState({
isEnglish: false,
IATitle: response.IAIdentifier,
inputDisabled: true,
});
} else {
if (response.error) Swal("Error!", response.message, "error");
else Swal("Voila!", response.message, "success");
Expand Down Expand Up @@ -344,6 +362,12 @@ class Books extends React.Component {
IATitle: response.titleInIA,
inputDisabled: true,
});
} else if (!isValidEnglishChar.test(response.IAIdentifier)) {
this.setState({
isEnglish: false,
IATitle: response.IAIdentifier,
inputDisabled: true,
});
} else {
if (response.error) Swal("Error!", response.message, "error");
else Swal("Voila!", response.message, "success");
Expand Down Expand Up @@ -379,53 +403,58 @@ class Books extends React.Component {
{this.renderContent(this.state.option)}
</div>
{this.state.isDuplicate ? (
<div
class="cdx-message cdx-message--block cdx-message--warning"
aria-live="polite"
style={{ marginTop: "20px", display: "inline-block" }}
>
<span class="cdx-message__icon"></span>
<div class="cdx-message__content">
A file with this identifier{" "}
<a href={`https://archive.org/details/${this.state.IATitle}`}>
(https://archive.org/{this.state.IATitle})
</a>{" "}
already exists at Internet Archive. Please enter a different
identifier to proceed.
<div className="cdx-text-input input-group">
<span className="input-group-addon helper" id="bid">
https://archive.org/details/
</span>
<input
className="cdx-text-input__input"
type="text"
id="IAIdentifier"
name="IAIdentifier"
onChange={(event) =>
this.setState({ IAIdentifier: event.target.value })
}
required
placeholder="Enter unique file identifier"
/>
</div>
</div>
</div>
<ChangeIdentifier
description={
<>
A file with this identifier{" "}
<a
href={`https://archive.org/details/${this.state.IATitle}`}
>
(https://archive.org/{this.state.IATitle})
</a>{" "}
already exists at Internet Archive. Please enter a different
identifier to proceed.
</>
}
inputPlaceholder="Enter unique file identifier"
onIdentifierChange={(event) =>
this.setState({ IAIdentifier: event.target.value })
}
/>
) : null}
{!this.state.isEnglish ? (
<ChangeIdentifier
description={
<>
The file you wish to upload has a non-english identifier -
{this.state.IATitle} which may cause problems when uploading
to internet archive. Please enter a valid English identifier
to proceed.
</>
}
inputPlaceholder="Enter a valid English Identifier"
onIdentifierChange={(event) =>
this.setState({ IAIdentifier: event.target.value })
}
/>
) : null}

{session && (
<div>
<div style={{ marginTop: 20, marginRight: 20 }}>
<button className="cdx-button cdx-button--action-progressive cdx-button--weight-primary">
Submit
</button>
{this.state.isDuplicate === true && (
{this.state.isDuplicate === true ||
this.state.isEnglish === false ? (
<button
onClick={this.onResetButtonClicked}
style={{ marginLeft: 40 }}
className="cdx-button cdx-button--action-progressive cdx-button--weight-primary"
>
Reset
</button>
)}
) : null}
</div>
</div>
)}
Expand Down
34 changes: 34 additions & 0 deletions components/ChangeIdentifier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const ChangeIdentifier = ({
description,
inputPlaceholder,
onIdentifierChange,
}) => {
return (
<div
className="cdx-message cdx-message--block cdx-message--warning"
aria-live="polite"
style={{ marginTop: "20px", display: "inline-block" }}
>
<span className="cdx-message__icon"></span>
<div className="cdx-message__content">
{description}
<div className="cdx-text-input input-group">
<span className="input-group-addon helper" id="bid">
https://archive.org/details/
</span>
<input
className="cdx-text-input__input"
type="text"
id="IAIdentifier"
name="IAIdentifier"
onChange={onIdentifierChange}
required
placeholder={inputPlaceholder}
/>
</div>
</div>
</div>
);
};

export default ChangeIdentifier;