+ issue cover uploading
+ comments and debug messages here and there
This commit is contained in:
parent
f81eb7b0b8
commit
6c3eed638e
|
|
@ -74,6 +74,7 @@ class Importer {
|
||||||
const cwd = path.dirname(xmlFilePath);
|
const cwd = path.dirname(xmlFilePath);
|
||||||
console.success("Processing directory:", path.relative(__dirname, cwd));
|
console.success("Processing directory:", path.relative(__dirname, cwd));
|
||||||
|
|
||||||
|
// Read XML file with issue data
|
||||||
const xmlData = fs.readFileSync(xmlFilePath, "utf-16le");
|
const xmlData = fs.readFileSync(xmlFilePath, "utf-16le");
|
||||||
const $xml = cheerio.load(xmlData, { xmlMode: true });
|
const $xml = cheerio.load(xmlData, { xmlMode: true });
|
||||||
|
|
||||||
|
|
@ -124,8 +125,17 @@ class Importer {
|
||||||
|
|
||||||
if (!year) info["showYear"] = "0";
|
if (!year) info["showYear"] = "0";
|
||||||
|
|
||||||
|
// First, upload issue cover if it exists
|
||||||
|
const coverImagePath = path.join(cwd, 'cover.jpg');
|
||||||
|
if (fs.existsSync(coverImagePath)) {
|
||||||
|
const issueCoverImageId = await Issue.uploadCover(this.client, journalSlug, coverImagePath);
|
||||||
|
if (issueCoverImageId) {
|
||||||
|
info.temporaryFileId = issueCoverImageId;
|
||||||
|
}
|
||||||
|
}
|
||||||
// console.log(info)
|
// console.log(info)
|
||||||
|
|
||||||
|
// Create issue in OJS. Uploaded cover will be attached by its id during creation
|
||||||
const issueId = await Issue.create(this.client, journalSlug, info);
|
const issueId = await Issue.create(this.client, journalSlug, info);
|
||||||
console.success("Got issue id:", issueId);
|
console.success("Got issue id:", issueId);
|
||||||
|
|
||||||
|
|
@ -139,7 +149,6 @@ class Importer {
|
||||||
`Creating submission ${i + 1}/${totalArticles} with issueId ${issueId}`
|
`Creating submission ${i + 1}/${totalArticles} with issueId ${issueId}`
|
||||||
);
|
);
|
||||||
var submissionInfo = await this.getArticleInfo(articleXML, cwd);
|
var submissionInfo = await this.getArticleInfo(articleXML, cwd);
|
||||||
|
|
||||||
submissionInfo["issueId"] = issueId;
|
submissionInfo["issueId"] = issueId;
|
||||||
|
|
||||||
// TODO validate info
|
// TODO validate info
|
||||||
|
|
@ -148,6 +157,7 @@ class Importer {
|
||||||
await this.submission.create(journalSlug, submissionInfo);
|
await this.submission.create(journalSlug, submissionInfo);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Publish the issue
|
||||||
await Issue.publish(this.client, journalSlug, issueId);
|
await Issue.publish(this.client, journalSlug, issueId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,8 @@ module.exports = {
|
||||||
issue: {
|
issue: {
|
||||||
getAll: '$$$call$$$/grid/issues/future-issue-grid/fetch-grid',
|
getAll: '$$$call$$$/grid/issues/future-issue-grid/fetch-grid',
|
||||||
create: '$$$call$$$/grid/issues/future-issue-grid/update-issue?issueId=',
|
create: '$$$call$$$/grid/issues/future-issue-grid/update-issue?issueId=',
|
||||||
publish: '$$$call$$$/grid/issues/future-issue-grid/publish-issue'
|
publish: '$$$call$$$/grid/issues/future-issue-grid/publish-issue',
|
||||||
|
uploadCover: '$$$call$$$/grid/issues/future-issue-grid/upload-file',
|
||||||
},
|
},
|
||||||
submission: {
|
submission: {
|
||||||
prepare: 'submission/step/1',
|
prepare: 'submission/step/1',
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
const fs = require("fs");
|
||||||
|
|
||||||
const endpoints = require('./endpoints')
|
const endpoints = require('./endpoints')
|
||||||
const form_data = require('./form-data')
|
const form_data = require('./form-data')
|
||||||
|
|
||||||
|
|
@ -32,7 +34,42 @@ exports.create = async (client, journalSlug, info = {}) => {
|
||||||
return diff(issueIdsAfter, issueIdsBefore)[0]
|
return diff(issueIdsAfter, issueIdsBefore)[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.uploadCover = async (client, journalSlug, imagePath) => {
|
||||||
|
var imageId;
|
||||||
|
const journalUrl = client.getJournalUrl(journalSlug);
|
||||||
|
|
||||||
|
console.log("Uploading issue cover:", imagePath);
|
||||||
|
|
||||||
|
const fileStream = fs.createReadStream(imagePath);
|
||||||
|
|
||||||
|
await client
|
||||||
|
.sendJson({
|
||||||
|
method: "POST",
|
||||||
|
baseUrl: journalUrl,
|
||||||
|
uri: endpoints.issue.uploadCover,
|
||||||
|
headers: {
|
||||||
|
browser_user_agent: client.apiDefaults.headers["User-Agent"]
|
||||||
|
},
|
||||||
|
formData: {
|
||||||
|
name: "name",
|
||||||
|
uploadedFile: fileStream
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(jsonData => {
|
||||||
|
console.info("Cover upload result:", jsonData);
|
||||||
|
|
||||||
|
// TODO Check JSON has certain info
|
||||||
|
if (!jsonData || !jsonData.temporaryFileId) Promise.reject();
|
||||||
|
|
||||||
|
imageId = jsonData.temporaryFileId;
|
||||||
|
})
|
||||||
|
.catch(err => console.error("Issue cover upload failed:", err));
|
||||||
|
|
||||||
|
return imageId;
|
||||||
|
}
|
||||||
|
|
||||||
exports.publish = async (client, journalSlug, issueId) => {
|
exports.publish = async (client, journalSlug, issueId) => {
|
||||||
|
console.info("Publishing issue...")
|
||||||
const journalUrl = client.getJournalUrl(journalSlug);
|
const journalUrl = client.getJournalUrl(journalSlug);
|
||||||
|
|
||||||
return client
|
return client
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user