mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-22 16:30:34 +01:00
image upload changes
This commit is contained in:
@@ -4,6 +4,13 @@ var config = {
|
|||||||
|
|
||||||
// "base_url" is expected to be a publically accessible URL to your NodeBB instance (Default base_url: 'http://localhost', port: '4567')
|
// "base_url" is expected to be a publically accessible URL to your NodeBB instance (Default base_url: 'http://localhost', port: '4567')
|
||||||
"base_url": "http://localhost",
|
"base_url": "http://localhost",
|
||||||
|
|
||||||
|
// public url for uploaded files
|
||||||
|
"upload_url": "http://dev.domain.com/uploads/",
|
||||||
|
|
||||||
|
// relative path for uploads
|
||||||
|
"upload_path": "/uploads/",
|
||||||
|
|
||||||
"use_port": true,
|
"use_port": true,
|
||||||
"port": 4567,
|
"port": 4567,
|
||||||
|
|
||||||
|
|||||||
@@ -198,11 +198,8 @@ $(document).ready(function() {
|
|||||||
hideAlerts();
|
hideAlerts();
|
||||||
$('#alert-error').text(message).show();
|
$('#alert-error').text(message).show();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
(function() {
|
|
||||||
|
|
||||||
function submitUserData() {
|
function submitUserData() {
|
||||||
var userData = {
|
var userData = {
|
||||||
uid:$('#inputUID').val(),
|
uid:$('#inputUID').val(),
|
||||||
@@ -236,101 +233,100 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$(document).ready(function(){
|
var selectedImageType = '';
|
||||||
|
|
||||||
var selectedImageType = '';
|
$('#submitBtn').on('click',function(){
|
||||||
|
|
||||||
$('#submitBtn').on('click',function(){
|
submitUserData();
|
||||||
|
|
||||||
submitUserData();
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
function updateImages() {
|
|
||||||
|
|
||||||
var currentPicture = $('#user-current-picture').attr('src');
|
|
||||||
var gravatarPicture = $('#user-data-gravatarpicture').html();
|
|
||||||
var uploadedPicture = $('#user-data-uploadedpicture').html();
|
|
||||||
|
|
||||||
if(gravatarPicture) {
|
|
||||||
$('#user-gravatar-picture').attr('src', gravatarPicture);
|
|
||||||
$('#gravatar-box').show();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
$('#gravatar-box').hide();
|
|
||||||
|
|
||||||
if(uploadedPicture) {
|
|
||||||
$('#user-uploaded-picture').attr('src', uploadedPicture);
|
|
||||||
$('#uploaded-box').show();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
$('#uploaded-box').hide();
|
|
||||||
|
|
||||||
|
|
||||||
if(currentPicture == gravatarPicture)
|
|
||||||
$('#gravatar-box .icon-ok').show();
|
|
||||||
else
|
|
||||||
$('#gravatar-box .icon-ok').hide();
|
|
||||||
|
|
||||||
if(currentPicture == uploadedPicture)
|
|
||||||
$('#uploaded-box .icon-ok').show();
|
|
||||||
else
|
|
||||||
$('#uploaded-box .icon-ok').hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$('#changePictureBtn').on('click', function() {
|
|
||||||
selectedImageType = '';
|
|
||||||
updateImages();
|
|
||||||
|
|
||||||
$('#change-picture-modal').modal('show');
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#gravatar-box').on('click', function(){
|
|
||||||
$('#gravatar-box .icon-ok').show();
|
|
||||||
$('#uploaded-box .icon-ok').hide();
|
|
||||||
selectedImageType = 'gravatar';
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#uploaded-box').on('click', function(){
|
|
||||||
$('#gravatar-box .icon-ok').hide();
|
|
||||||
$('#uploaded-box .icon-ok').show();
|
|
||||||
selectedImageType = 'uploaded';
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#savePictureChangesBtn').on('click', function() {
|
|
||||||
$('#change-picture-modal').modal('hide');
|
|
||||||
|
|
||||||
if(selectedImageType) {
|
|
||||||
changeUserPicture(selectedImageType);
|
|
||||||
|
|
||||||
if(selectedImageType == 'gravatar')
|
|
||||||
$('#user-current-picture').attr('src', $('#user-data-gravatarpicture').html());
|
|
||||||
else if(selectedImageType == 'uploaded')
|
|
||||||
$('#user-current-picture').attr('src', $('#user-data-uploadedpicture').html());
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#upload-picture-modal').on('hide', function() {
|
|
||||||
$('#userPhotoInput').val('');
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#uploadPictureBtn').on('click', function(){
|
|
||||||
|
|
||||||
$('#change-picture-modal').modal('hide');
|
|
||||||
$('#upload-picture-modal').modal('show');
|
|
||||||
|
|
||||||
$('#pictureUploadSubmitBtn').on('click', function() {
|
|
||||||
$('#uploadForm').submit();
|
|
||||||
});
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}());
|
|
||||||
|
|
||||||
|
function updateImages() {
|
||||||
|
|
||||||
|
var currentPicture = $('#user-current-picture').attr('src');
|
||||||
|
var gravatarPicture = $('#user-data-gravatarpicture').html();
|
||||||
|
var uploadedPicture = $('#user-data-uploadedpicture').html();
|
||||||
|
|
||||||
|
if(gravatarPicture) {
|
||||||
|
$('#user-gravatar-picture').attr('src', gravatarPicture);
|
||||||
|
$('#gravatar-box').show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$('#gravatar-box').hide();
|
||||||
|
|
||||||
|
if(uploadedPicture) {
|
||||||
|
$('#user-uploaded-picture').attr('src', uploadedPicture);
|
||||||
|
$('#uploaded-box').show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$('#uploaded-box').hide();
|
||||||
|
|
||||||
|
|
||||||
|
if(currentPicture == gravatarPicture)
|
||||||
|
$('#gravatar-box .icon-ok').show();
|
||||||
|
else
|
||||||
|
$('#gravatar-box .icon-ok').hide();
|
||||||
|
|
||||||
|
if(currentPicture == uploadedPicture)
|
||||||
|
$('#uploaded-box .icon-ok').show();
|
||||||
|
else
|
||||||
|
$('#uploaded-box .icon-ok').hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$('#changePictureBtn').on('click', function() {
|
||||||
|
selectedImageType = '';
|
||||||
|
updateImages();
|
||||||
|
|
||||||
|
$('#change-picture-modal').modal('show');
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#gravatar-box').on('click', function(){
|
||||||
|
$('#gravatar-box .icon-ok').show();
|
||||||
|
$('#uploaded-box .icon-ok').hide();
|
||||||
|
selectedImageType = 'gravatar';
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#uploaded-box').on('click', function(){
|
||||||
|
$('#gravatar-box .icon-ok').hide();
|
||||||
|
$('#uploaded-box .icon-ok').show();
|
||||||
|
selectedImageType = 'uploaded';
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#savePictureChangesBtn').on('click', function() {
|
||||||
|
$('#change-picture-modal').modal('hide');
|
||||||
|
|
||||||
|
if(selectedImageType) {
|
||||||
|
changeUserPicture(selectedImageType);
|
||||||
|
|
||||||
|
if(selectedImageType == 'gravatar')
|
||||||
|
$('#user-current-picture').attr('src', $('#user-data-gravatarpicture').html());
|
||||||
|
else if(selectedImageType == 'uploaded')
|
||||||
|
$('#user-current-picture').attr('src', $('#user-data-uploadedpicture').html());
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#upload-picture-modal').on('hide', function() {
|
||||||
|
$('#userPhotoInput').val('');
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#uploadPictureBtn').on('click', function(){
|
||||||
|
|
||||||
|
$('#change-picture-modal').modal('hide');
|
||||||
|
$('#upload-picture-modal').modal('show');
|
||||||
|
hideAlerts();
|
||||||
|
|
||||||
|
$('#pictureUploadSubmitBtn').on('click', function() {
|
||||||
|
$('#uploadForm').submit();
|
||||||
|
});
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
@@ -241,11 +241,14 @@ var express = require('express'),
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var uploadPath = config['upload_path'] + uid + '-' + filename;
|
filename = uid + '-' + filename
|
||||||
|
var uploadPath = config.upload_path + filename;
|
||||||
|
|
||||||
|
console.log(uploadPath);
|
||||||
|
|
||||||
fs.rename(
|
fs.rename(
|
||||||
tempPath,
|
tempPath,
|
||||||
global.configuration['ROOT_DIRECTORY']+ uploadPath,
|
global.configuration['ROOT_DIRECTORY'] + uploadPath,
|
||||||
function(error) {
|
function(error) {
|
||||||
if(error) {
|
if(error) {
|
||||||
res.send({
|
res.send({
|
||||||
@@ -254,7 +257,7 @@ var express = require('express'),
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var imageUrl = config.base_url + config.install_path + uploadPath;
|
var imageUrl = config.upload_url + filename;
|
||||||
|
|
||||||
res.send({
|
res.send({
|
||||||
path: imageUrl
|
path: imageUrl
|
||||||
|
|||||||
Reference in New Issue
Block a user