diff --git a/bull/commons-queue/consumer.js b/bull/commons-queue/consumer.js
index a3eab3b..30e3737 100644
--- a/bull/commons-queue/consumer.js
+++ b/bull/commons-queue/consumer.js
@@ -4,7 +4,8 @@ const winston = require("winston");
const {
downloadFile,
uploadToCommons,
- convertZipToPdf,
+ uploadToWikiData,
+ convertZipToPdf
} = require("../../utils/helper");
const JSZip = require("jszip");
const logger = winston.loggers.get("defaultLogger");
@@ -83,4 +84,26 @@ CommonsQueue.process(async (job, done) => {
});
return done(null, true);
}
-});
+ const wikiDataResponse = await uploadToWikiData(
+ job.data.metadata,
+ commonsResponse.filename
+ );
+ if (wikiDataResponse !== 404) {
+ process.emit(`commonsJobComplete:${job.id}`, {
+ status: true,
+ value: {
+ commons: commonsResponse,
+ wikidata: wikiDataResponse,
+ },
+ });
+ } else {
+ process.emit(`commonsJobComplete:${job.id}`, {
+ status: true,
+ value: {
+ commons: commonsResponse,
+ wikidata: 404,
+ },
+ });
+ }
+ return done(null, true);
+});
\ No newline at end of file
diff --git a/bull/google-books-queue/consumer.js b/bull/google-books-queue/consumer.js
index 9942e8d..d4f8142 100644
--- a/bull/google-books-queue/consumer.js
+++ b/bull/google-books-queue/consumer.js
@@ -126,7 +126,11 @@ GoogleBooksQueue.process((job, done) => {
step: "Upload to Wikimedia Commons",
value: `(${100}%)`,
wikiLinks: {
- commons: await commonsResponse.value.filename,
+ commons: await commonsResponse.value.commons.filename,
+ wikidata:
+ (await commonsResponse.value.wikidata) !== 404
+ ? await commonsResponse.value.wikidata
+ : 404,
},
});
if (job.data.isEmailNotification === "true") {
diff --git a/bull/trove-queue/consumer.js b/bull/trove-queue/consumer.js
index 310e5ba..369ef28 100644
--- a/bull/trove-queue/consumer.js
+++ b/bull/trove-queue/consumer.js
@@ -107,6 +107,12 @@ TroveQueue.process((job, done) => {
step: "Upload To IA",
value: `(${100}%)`,
});
+ if (
+ isEmailNotification !== "true" &&
+ job.data.details.isUploadCommons !== "true"
+ ) {
+ done(null, true);
+ }
if (
isEmailNotification === "true" &&
job.data.details.isUploadCommons !== "true"
@@ -129,9 +135,14 @@ TroveQueue.process((job, done) => {
if (commonsResponse.status === true) {
job.progress({
step: "Upload to Wikimedia Commons",
- value: `(100%)`,
+ value: `(${100}%)`,
wikiLinks: {
- commons: await commonsResponse.value.filename,
+ commons: await commonsResponse.value.commons
+ .filename,
+ wikidata:
+ (await commonsResponse.value.wikidata) !== 404
+ ? await commonsResponse.value.wikidata
+ : 404,
},
});
if (job.data.isEmailNotification === "true") {
@@ -141,7 +152,10 @@ TroveQueue.process((job, done) => {
EmailProducer(
userName,
name,
- { archiveLink: trueURI, commonsLink: commonsLink },
+ {
+ archiveLink: trueURI,
+ commonsLink: commonsLink,
+ },
{ archive: true, commons: true }
);
}
diff --git a/components/ShowJobInformation.js b/components/ShowJobInformation.js
index 542456f..ff56f78 100644
--- a/components/ShowJobInformation.js
+++ b/components/ShowJobInformation.js
@@ -144,10 +144,10 @@ const ShowJobInformation = (props) => {
- {data.wikimedia_links !== "Not Integrated" ? (
+ {data.wikimedia_links.commons !== "Not Integrated" ? (
+
+ {data.wikimedia_links.wikidata !== "Not Integrated" ? (
+
+
+
+ ) : null}
+
);
diff --git a/server.js b/server.js
index 618d8cc..f4b4926 100644
--- a/server.js
+++ b/server.js
@@ -188,9 +188,14 @@ app
uploadLink: getUploadLink(job, trueURI),
isUploaded: jobState === "completed" ? true : false,
},
- wikimedia_links: job.progress().wikiLinks?.commons
- ? job.progress().wikiLinks.commons
- : "Not Integrated",
+ wikimedia_links: {
+ commons: job.progress().wikiLinks?.commons
+ ? job.progress().wikiLinks.commons
+ : "Not Integrated",
+ wikidata: job.progress().wikiLinks?.wikidata
+ ? job.progress().wikiLinks.wikidata
+ : "Not Integrated",
+ },
};
res.send(
diff --git a/utils/helper.js b/utils/helper.js
index 4165cba..2a2f031 100644
--- a/utils/helper.js
+++ b/utils/helper.js
@@ -397,4 +397,244 @@ module.exports = {
return error;
}
},
+ uploadToWikiData: async (metadata, commonsItemFilename) => {
+ const bot = await Mwn.init({
+ apiUrl: "https://www.wikidata.org/w/api.php",
+ OAuth2AccessToken: metadata.oauthToken,
+ userAgent: "bub2.toolforge ([[https://bub2.toolforge.org]])",
+ defaultParams: {
+ assert: "user",
+ },
+ });
+
+ async function createEntity(csrf_token) {
+ try {
+ const title = metadata.details.volumeInfo.title || "";
+ const id = metadata.details.id || "";
+ const authorsArr = metadata.details.volumeInfo.authors
+ ? metadata.details.volumeInfo.authors.join().trim()
+ : null;
+ const authors = authorsArr || "";
+ // Mapping for the labels/properties defined in `payload` - https://prop-explorer.toolforge.org/
+ const payload = {
+ labels: {
+ en: {
+ language: "en",
+ value: commonsItemFilename,
+ },
+ },
+ descriptions: {
+ en: {
+ language: "en",
+ value: title,
+ },
+ },
+ claims: {
+ file_name: [
+ {
+ mainsnak: {
+ snaktype: "value",
+ property: "P18",
+ datavalue: {
+ value: commonsItemFilename,
+ type: "string",
+ },
+ },
+ type: "statement",
+ rank: "normal",
+ },
+ ],
+ file_url: [
+ {
+ mainsnak: {
+ snaktype: "value",
+ property: "P4765",
+ datavalue: {
+ value: `https://commons.wikimedia.org/wiki/File:${commonsItemFilename}`,
+ type: "string",
+ },
+ },
+ type: "statement",
+ rank: "normal",
+ },
+ ],
+ commons_category: [
+ {
+ mainsnak: {
+ snaktype: "value",
+ property: "P373",
+ datavalue: {
+ value: "Bub.wikimedia",
+ type: "string",
+ },
+ },
+ type: "statement",
+ rank: "normal",
+ },
+ ],
+ internet_archive_id: id
+ ? [
+ {
+ mainsnak: {
+ snaktype: "value",
+ property: "P724",
+ datavalue: {
+ value: id,
+ type: "string",
+ },
+ },
+ type: "statement",
+ rank: "normal",
+ },
+ ]
+ : undefined,
+ collection: [
+ {
+ mainsnak: {
+ snaktype: "value",
+ property: "P195",
+ datavalue: {
+ value: {
+ "entity-type": "item",
+ "numeric-id": 39162,
+ id: "Q39162", //wikidataID for 'opensource'
+ },
+ type: "wikibase-entityid",
+ },
+ },
+ type: "statement",
+ rank: "normal",
+ },
+ ],
+ title: title
+ ? [
+ {
+ mainsnak: {
+ snaktype: "value",
+ property: "P1476",
+ datavalue: {
+ value: {
+ text: title,
+ language: "en",
+ },
+ type: "monolingualtext",
+ },
+ },
+ type: "statement",
+ rank: "normal",
+ },
+ ]
+ : undefined,
+ name: title
+ ? [
+ {
+ mainsnak: {
+ snaktype: "value",
+ property: "P2561",
+ datavalue: {
+ value: {
+ text: title,
+ language: "en",
+ },
+ type: "monolingualtext",
+ },
+ },
+ type: "statement",
+ rank: "normal",
+ },
+ ]
+ : undefined,
+ file_format: [
+ {
+ mainsnak: {
+ snaktype: "value",
+ property: "P2701",
+ datavalue: {
+ value: {
+ "entity-type": "item",
+ "numeric-id": 42332,
+ id: "Q42332", // wikidataID for PDF
+ },
+ type: "wikibase-entityid",
+ },
+ },
+ type: "statement",
+ rank: "normal",
+ },
+ ],
+ author_name: authors
+ ? [
+ {
+ mainsnak: {
+ snaktype: "value",
+ property: "P2093",
+ datavalue: {
+ value: authors,
+ type: "string",
+ },
+ },
+ type: "statement",
+ rank: "normal",
+ },
+ ]
+ : undefined,
+ URL: [
+ {
+ mainsnak: {
+ snaktype: "value",
+ property: "P2699",
+ datavalue: {
+ value: `https://commons.wikimedia.org/wiki/File:${commonsItemFilename}`,
+ type: "string",
+ },
+ },
+ type: "statement",
+ rank: "normal",
+ },
+ ],
+ copyright_status: [
+ {
+ mainsnak: {
+ snaktype: "value",
+ property: "P6216",
+ datavalue: {
+ value: {
+ "entity-type": "item",
+ "numeric-id": 6938433,
+ id: "Q6938433", // wikidataID for CC0 license
+ },
+ type: "wikibase-entityid",
+ },
+ },
+ type: "statement",
+ rank: "normal",
+ },
+ ],
+ },
+ };
+
+ const res = await bot.request({
+ action: "wbeditentity",
+ new: "item",
+ summary: "bub2.toolforge.org: upload commons item to wikidata",
+ tags: "wikimedia-commons-app",
+ data: JSON.stringify(payload),
+ token: csrf_token,
+ });
+ logger.log({
+ level: "info",
+ message: `uploadToWikidata: Upload of ${commonsItemFilename} metadata to wikidata successful`,
+ });
+ return res.entity.id;
+ } catch (error) {
+ logger.log({
+ level: "error",
+ message: `uploadToWikidata:${error}`,
+ });
+ return 404;
+ }
+ }
+ const csrf_token = await bot.getCsrfToken();
+ return await createEntity(csrf_token);
+ },
};