tested basic client scenarios
This commit is contained in:
parent
592fbb79d8
commit
9a93b3cc8d
3 changed files with 13 additions and 13 deletions
|
@ -58,19 +58,15 @@ module.exports = {
|
||||||
},
|
},
|
||||||
parsePublishApiChannel ({channelName, channelPassword}, user) {
|
parsePublishApiChannel ({channelName, channelPassword}, user) {
|
||||||
logger.debug('publish api parser input:', {channelName, channelPassword, user});
|
logger.debug('publish api parser input:', {channelName, channelPassword, user});
|
||||||
// if no channel name provided, publish will be anonymous
|
|
||||||
// if anonymous or '' provided, publish will be anonymous (even if client is logged in)
|
// if anonymous or '' provided, publish will be anonymous (even if client is logged in)
|
||||||
if (channelName === 'anonymous' || channelName === '') {
|
|
||||||
channelName = null;
|
|
||||||
}
|
|
||||||
// if a channel name is provided...
|
// if a channel name is provided...
|
||||||
if (channelName) {
|
if (channelName) {
|
||||||
// make sure a password was provided
|
// make sure a password was provided if no user token is provided
|
||||||
if (!channelPassword) {
|
if (!user && !channelPassword) {
|
||||||
throw new Error('Channel name provided without password');
|
throw new Error('Unauthenticated channel name provided without password');
|
||||||
}
|
}
|
||||||
// if request comes from the client and is logged in
|
// if request comes from the client with a token
|
||||||
// ensure it is the same channel and get the password
|
// ensure this publish uses that channel name
|
||||||
if (user) {
|
if (user) {
|
||||||
channelName = user.channelName;
|
channelName = user.channelName;
|
||||||
} ;
|
} ;
|
||||||
|
|
|
@ -78,17 +78,20 @@ const publishFileFunctions = {
|
||||||
const licenseInput = document.getElementById('publish-license');
|
const licenseInput = document.getElementById('publish-license');
|
||||||
const nsfwInput = document.getElementById('publish-nsfw');
|
const nsfwInput = document.getElementById('publish-nsfw');
|
||||||
const thumbnailInput = document.getElementById('claim-thumbnail-input');
|
const thumbnailInput = document.getElementById('claim-thumbnail-input');
|
||||||
|
const channelName = this.returnNullOrChannel();
|
||||||
return {
|
let metadata = {
|
||||||
name: nameInput.value.trim(),
|
name: nameInput.value.trim(),
|
||||||
channelName: this.returnNullOrChannel(),
|
|
||||||
title: titleInput.value.trim(),
|
title: titleInput.value.trim(),
|
||||||
description: descriptionInput.value.trim(),
|
description: descriptionInput.value.trim(),
|
||||||
license: licenseInput.value.trim(),
|
license: licenseInput.value.trim(),
|
||||||
nsfw: nsfwInput.checked,
|
nsfw: nsfwInput.checked,
|
||||||
type: stagedFiles[0].type,
|
type: stagedFiles[0].type,
|
||||||
thumbnail: thumbnailInput.value.trim(),
|
thumbnail: thumbnailInput.value.trim(),
|
||||||
|
};
|
||||||
|
if (channelName) {
|
||||||
|
metadata['channelName'] = channelName;
|
||||||
}
|
}
|
||||||
|
return metadata;
|
||||||
},
|
},
|
||||||
appendDataToFormData: function (file, metadata) {
|
appendDataToFormData: function (file, metadata) {
|
||||||
var fd = new FormData();
|
var fd = new FormData();
|
||||||
|
@ -143,7 +146,7 @@ const publishFileFunctions = {
|
||||||
publishStagedFile: function (event) {
|
publishStagedFile: function (event) {
|
||||||
event.preventDefault(); // prevent default so this script can handle submission
|
event.preventDefault(); // prevent default so this script can handle submission
|
||||||
const metadata = this.createMetadata();
|
const metadata = this.createMetadata();
|
||||||
const that = this; // note: necessary ?
|
const that = this;
|
||||||
const fileSelectionInputError = document.getElementById('input-error-file-selection');
|
const fileSelectionInputError = document.getElementById('input-error-file-selection');
|
||||||
const claimNameError = document.getElementById('input-error-claim-name');
|
const claimNameError = document.getElementById('input-error-claim-name');
|
||||||
const channelSelectError = document.getElementById('input-error-channel-select');
|
const channelSelectError = document.getElementById('input-error-channel-select');
|
||||||
|
|
|
@ -125,6 +125,7 @@ module.exports = (app) => {
|
||||||
});
|
});
|
||||||
// route to run a publish request on the daemon
|
// route to run a publish request on the daemon
|
||||||
app.post('/api/claim-publish', multipartMiddleware, ({ body, files, ip, originalUrl, user }, res) => {
|
app.post('/api/claim-publish', multipartMiddleware, ({ body, files, ip, originalUrl, user }, res) => {
|
||||||
|
logger.debug('api/claim-publish body:', body);
|
||||||
let name, fileName, filePath, fileType, nsfw, license, title, description, thumbnail, channelName, channelPassword;
|
let name, fileName, filePath, fileType, nsfw, license, title, description, thumbnail, channelName, channelPassword;
|
||||||
// validate the body and files of the request
|
// validate the body and files of the request
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue