v1.18.x
psychobunny 8 years ago
commit 631592b818

@ -107,10 +107,10 @@
"more_guests": "ゲストさんが%1人",
"users_and_others": "%1と他は%2",
"sort_by": "並び替え",
"oldest_to_newest": "新しい順",
"newest_to_oldest": "古い順",
"most_votes": "最高評価",
"most_posts": "最高投稿",
"oldest_to_newest": "古い\bものから新しい順",
"newest_to_oldest": "新しいものから古い順",
"most_votes": "最も投票された順",
"most_posts": "最も投稿された順",
"stale.title": "新しいスレッドを作りますか?",
"stale.warning": "あなたが返信しようとしてるスレッドが古いスレッドです。新しいスレッドを作って、そしてこのスレッドが参考として入れた方を勧めます。そうしますか?",
"stale.create": "新しいスレッドを作ります。",

@ -1,7 +1,7 @@
{
"posts": "İletiler",
"allow-files": "Allow users to upload regular files",
"private": "Make uploaded files private",
"private": "Yüklenen dosyaları gizli yap",
"max-image-width": "Resize images down to specified width (in pixels)",
"max-image-width-help": "(in pixels, default: 760 pixels, set to 0 to disable)",
"max-file-size": "Maksimum Dosya Boyutu (KiB)",
@ -19,10 +19,10 @@
"profile-image-dimension-help": "(in pixels, default: 128 pixels)",
"max-profile-image-size": "Maximum Profile Image File Size",
"max-profile-image-size-help": "(in kilobytes, default: 256 KiB)",
"max-cover-image-size": "Maximum Cover Image File Size",
"max-cover-image-size": "Maksimum Kapak Görseli Dosya Boyutu",
"max-cover-image-size-help": "(in kilobytes, default: 2,048 KiB)",
"keep-all-user-images": "Keep old versions of avatars and profile covers on the server",
"profile-covers": "Profile Covers",
"default-covers": "Default Cover Images",
"profile-covers": "Profil Kapakları",
"default-covers": "Varsayılan Kapak Görseli",
"default-covers-help": "Add comma-separated default cover images for accounts that don't have an uploaded cover image"
}

@ -18,7 +18,7 @@ define('pictureCropper', ['translator', 'cropper'], function (translator, croppe
uploadModal = $(uploadModal);
uploadModal.modal('show');
uploadModal.on('hidden.bs.modal', function () {
uploadModal.on('hidden.bs.modal', function () {
uploadModal.remove();
});
@ -31,9 +31,11 @@ define('pictureCropper', ['translator', 'cropper'], function (translator, croppe
});
};
module.handleImageCrop = function (data, callback) {
module.handleImageCrop = function (data, callback) {
$('#crop-picture-modal').remove();
templates.parse('modals/crop_picture', {url: data.url}, function (cropperHtml) {
templates.parse('modals/crop_picture', {
url: data.url
}, function (cropperHtml) {
translator.translate(cropperHtml, function (translated) {
var cropperModal = $(translated);
cropperModal.modal('show');
@ -58,28 +60,28 @@ define('pictureCropper', ['translator', 'cropper'], function (translator, croppe
cropperModal.find('.reset').on('click', function () {
cropperTool.reset();
});
cropperModal.find('.crop-btn').on('click', function () {
$(this).addClass('disabled');
var imageData = data.imageType ? cropperTool.getCroppedCanvas().toDataURL(data.imageType) : cropperTool.getCroppedCanvas().toDataURL();
cropperModal.find('#upload-progress-bar').css('width', '100%');
cropperModal.find('#upload-progress-box').show().removeClass('hide');
var socketData = {};
socketData[data.paramName] = data.paramValue;
socketData['imageData'] = imageData;
socket.emit(data.socketMethod, socketData, function (err, imageData) {
if (err) {
cropperModal.find('#upload-progress-box').hide();
cropperModal.find('.upload-btn').removeClass('disabled');
cropperModal.find('.crop-btn').removeClass('disabled');
return app.alertError(err.message);
}
callback(imageData.url);
cropperModal.modal('hide');
if (err) {
cropperModal.find('#upload-progress-box').hide();
cropperModal.find('.upload-btn').removeClass('disabled');
cropperModal.find('.crop-btn').removeClass('disabled');
return app.alertError(err.message);
}
callback(imageData.url);
cropperModal.modal('hide');
});
});
@ -115,8 +117,8 @@ define('pictureCropper', ['translator', 'cropper'], function (translator, croppe
return showAlert('error', '[[uploads:select-file-to-upload]]');
}
var file = fileInput[0].files[0];
var reader = new FileReader();
var file = fileInput[0].files[0];
var reader = new FileReader();
var imageUrl;
var imageType = file.type;

@ -59,7 +59,10 @@ function uploadAsImage(req, uploadedFile, callback) {
return next(new Error('[[error:no-privileges]]'));
}
if (plugins.hasListeners('filter:uploadImage')) {
return plugins.fireHook('filter:uploadImage', {image: uploadedFile, uid: req.uid}, callback);
return plugins.fireHook('filter:uploadImage', {
image: uploadedFile,
uid: req.uid
}, callback);
}
file.isFileTypeAllowed(uploadedFile.path, next);
},
@ -156,7 +159,10 @@ uploadsController.uploadThumb = function (req, res, next) {
}
if (plugins.hasListeners('filter:uploadImage')) {
return plugins.fireHook('filter:uploadImage', {image: uploadedFile, uid: req.uid}, next);
return plugins.fireHook('filter:uploadImage', {
image: uploadedFile,
uid: req.uid
}, next);
}
uploadFile(req.uid, uploadedFile, next);
@ -167,11 +173,17 @@ uploadsController.uploadThumb = function (req, res, next) {
uploadsController.uploadGroupCover = function (uid, uploadedFile, callback) {
if (plugins.hasListeners('filter:uploadImage')) {
return plugins.fireHook('filter:uploadImage', {image: uploadedFile, uid: uid}, callback);
return plugins.fireHook('filter:uploadImage', {
image: uploadedFile,
uid: uid
}, callback);
}
if (plugins.hasListeners('filter:uploadFile')) {
return plugins.fireHook('filter:uploadFile', {file: uploadedFile, uid: uid}, callback);
return plugins.fireHook('filter:uploadFile', {
file: uploadedFile,
uid: uid
}, callback);
}
file.isFileTypeAllowed(uploadedFile.path, function (err) {
@ -184,7 +196,10 @@ uploadsController.uploadGroupCover = function (uid, uploadedFile, callback) {
function uploadFile(uid, uploadedFile, callback) {
if (plugins.hasListeners('filter:uploadFile')) {
return plugins.fireHook('filter:uploadFile', {file: uploadedFile, uid: uid}, callback);
return plugins.fireHook('filter:uploadFile', {
file: uploadedFile,
uid: uid
}, callback);
}
if (!uploadedFile) {
@ -197,7 +212,7 @@ function uploadFile(uid, uploadedFile, callback) {
if (meta.config.hasOwnProperty('allowedFileExtensions')) {
var allowed = file.allowedExtensions();
var extension = typeToExtension(uploadedFile.type);
var extension = file.typeToExtension(uploadedFile.type);
if (!extension || (allowed.length > 0 && allowed.indexOf(extension) === -1)) {
return callback(new Error('[[error:invalid-file-type, ' + allowed.join(', ') + ']]'));
}
@ -207,7 +222,7 @@ function uploadFile(uid, uploadedFile, callback) {
}
function saveFileToLocal(uploadedFile, callback) {
var extension = typeToExtension(uploadedFile.type);
var extension = file.typeToExtension(uploadedFile.type);
if (!extension) {
return callback(new Error('[[error:invalid-extension]]'));
}
@ -228,14 +243,6 @@ function saveFileToLocal(uploadedFile, callback) {
});
}
function typeToExtension(type) {
var extension;
if (type) {
extension = '.' + mime.extension(type);
}
return extension;
}
function deleteTempFiles(files) {
async.each(files, function (file, next) {
fs.unlink(file.path, function (err) {
@ -247,6 +254,4 @@ function deleteTempFiles(files) {
});
}
module.exports = uploadsController;

@ -6,6 +6,7 @@ var path = require('path');
var winston = require('winston');
var jimp = require('jimp');
var mkdirp = require('mkdirp');
var mime = require('mime');
var utils = require('../public/src/utils');
@ -13,8 +14,8 @@ var file = {};
file.saveFileToLocal = function (filename, folder, tempPath, callback) {
/*
* remarkable doesn't allow spaces in hyperlinks, once that's fixed, remove this.
*/
* remarkable doesn't allow spaces in hyperlinks, once that's fixed, remove this.
*/
filename = filename.split('.');
filename.forEach(function (name, idx) {
filename[idx] = utils.slugify(name);
@ -100,7 +101,8 @@ file.existsSync = function (path) {
var exists = false;
try {
exists = fs.statSync(path);
} catch(err) {
}
catch (err) {
exists = false;
}
@ -110,7 +112,8 @@ file.existsSync = function (path) {
file.link = function link(filePath, destPath, cb) {
if (process.platform === 'win32') {
fs.link(filePath, destPath, cb);
} else {
}
else {
fs.symlink(filePath, destPath, 'file', cb);
}
};
@ -120,4 +123,12 @@ file.linkDirs = function linkDirs(sourceDir, destDir, callback) {
fs.symlink(sourceDir, destDir, type, callback);
};
file.typeToExtension = function (type) {
var extension;
if (type) {
extension = '.' + mime.extension(type);
}
return extension;
};
module.exports = file;

@ -99,6 +99,7 @@ function setupConfigs() {
nconf.set('use_port', !!urlObject.port);
nconf.set('relative_path', relativePath);
nconf.set('port', urlObject.port || nconf.get('port') || nconf.get('PORT') || (nconf.get('PORT_ENV_VAR') ? nconf.get(nconf.get('PORT_ENV_VAR')) : false) || 4567);
nconf.set('upload_url', '/assets/uploads');
}
function printStartupInfo() {

@ -43,7 +43,10 @@ module.exports = function (User) {
async.waterfall([
function (next) {
if (plugins.hasListeners('filter:uploadImage')) {
return plugins.fireHook('filter:uploadImage', {image: picture, uid: updateUid}, next);
return plugins.fireHook('filter:uploadImage', {
image: picture,
uid: updateUid
}, next);
}
var filename = updateUid + '-profileimg' + (keepAllVersions ? '-' + Date.now() : '') + (convertToPNG ? '.png' : extension);
@ -79,7 +82,10 @@ module.exports = function (User) {
},
function (_image, next) {
uploadedImage = _image;
User.setUserFields(updateUid, {uploadedpicture: uploadedImage.url, picture: uploadedImage.url}, next);
User.setUserFields(updateUid, {
uploadedpicture: uploadedImage.url,
picture: uploadedImage.url
}, next);
},
function (next) {
next(null, uploadedImage);
@ -92,32 +98,41 @@ module.exports = function (User) {
return callback(new Error('[[error:no-plugin]]'));
}
request.head(url, function (err, res) {
if (err) {
return callback(err);
}
var uploadSize = parseInt(meta.config.maximumProfileImageSize, 10) || 256;
var size = res.headers['content-length'];
var type = res.headers['content-type'];
var extension = mime.extension(type);
if (['png', 'jpeg', 'jpg', 'gif'].indexOf(extension) === -1) {
return callback(new Error('[[error:invalid-image-extension]]'));
}
async.waterfall([
function (next) {
request.head(url, next);
},
function (res, body, next) {
var uploadSize = parseInt(meta.config.maximumProfileImageSize, 10) || 256;
var size = res.headers['content-length'];
var type = res.headers['content-type'];
var extension = mime.extension(type);
if (size > uploadSize * 1024) {
return callback(new Error('[[error:file-too-big, ' + uploadSize + ']]'));
}
if (['png', 'jpeg', 'jpg', 'gif'].indexOf(extension) === -1) {
return callback(new Error('[[error:invalid-image-extension]]'));
}
var picture = {url: url, name: ''};
plugins.fireHook('filter:uploadImage', {image: picture, uid: uid}, function (err, image) {
if (err) {
return callback(err);
if (size > uploadSize * 1024) {
return callback(new Error('[[error:file-too-big, ' + uploadSize + ']]'));
}
User.setUserFields(uid, {uploadedpicture: image.url, picture: image.url});
callback(null, image);
});
});
plugins.fireHook('filter:uploadImage', {
uid: uid,
image: {
url: url,
name: ''
}
}, next);
},
function (image, next) {
User.setUserFields(uid, {
uploadedpicture: image.url,
picture: image.url
}, function (err) {
next(err, image);
});
}
], callback);
};
User.updateCoverPosition = function (uid, position, callback) {
@ -125,8 +140,12 @@ module.exports = function (User) {
};
User.updateCoverPicture = function (data, callback) {
var keepAllVersions = parseInt(meta.config['profile:keepAllUserImages'], 10) === 1;
var url, md5sum;
var url;
var image = {
name: 'profileCover',
uid: data.uid
};
if (!data.imageData && data.position) {
return User.updateCoverPosition(data.uid, data.position, callback);
@ -145,160 +164,134 @@ module.exports = function (User) {
}
if (data.file) {
return next();
return setImmediate(next, null, data.file.path);
}
md5sum = crypto.createHash('md5');
md5sum.update(data.imageData);
md5sum = md5sum.digest('hex');
data.file = {
path: path.join(os.tmpdir(), md5sum)
};
var buffer = new Buffer(data.imageData.slice(data.imageData.indexOf('base64') + 7), 'base64');
fs.writeFile(data.file.path, buffer, {
encoding: 'base64'
}, next);
saveImageDataToTempFile(data.imageData, next);
},
function (next) {
var image = {
name: 'profileCover',
path: data.file.path,
uid: data.uid
};
if (plugins.hasListeners('filter:uploadImage')) {
return plugins.fireHook('filter:uploadImage', {image: image, uid: data.uid}, next);
}
function (path, next) {
image.path = path;
var filename = data.uid + '-profilecover' + (keepAllVersions ? '-' + Date.now() : '');
async.waterfall([
function (next) {
file.isFileTypeAllowed(data.file.path, next);
},
function (next) {
file.saveFileToLocal(filename, 'profile', image.path, next);
},
function (upload, next) {
next(null, {
url: nconf.get('relative_path') + upload.url,
name: image.name
});
}
], next);
uploadProfileOrCover('profilecover', image, data.imageData, next);
},
function (uploadData, next) {
url = uploadData.url;
User.setUserField(data.uid, 'cover:url', uploadData.url, next);
},
function (next) {
fs.unlink(data.file.path, function (err) {
if (err) {
winston.error(err);
}
next();
});
if (data.position) {
User.updateCoverPosition(data.uid, data.position, next);
} else {
setImmediate(next);
}
}
], function (err) {
if (err) {
return fs.unlink(data.file.path, function (unlinkErr) {
if (unlinkErr) {
winston.error(unlinkErr);
}
callback(err); // send back the original error
});
}
if (data.position) {
User.updateCoverPosition(data.uid, data.position, function (err) {
callback(err, {url: url});
});
} else {
callback(err, {url: url});
}
deleteFile(image.path);
callback(err, {
url: url
});
});
};
User.uploadCroppedPicture = function (data, callback) {
var keepAllVersions = parseInt(meta.config['profile:keepAllUserImages'], 10) === 1;
var url, md5sum;
var url;
var image = {
name: 'profileAvatar',
uid: data.uid
};
if (!data.imageData) {
return callback(new Error('[[error:invalid-data]]'));
}
async.waterfall([
function (next) {
var size = data.file ? data.file.size : data.imageData.length;
var size = data.imageData.length;
var uploadSize = parseInt(meta.config.maximumProfileImageSize, 10) || 256;
if (size > uploadSize * 1024) {
return next(new Error('[[error:file-too-big, ' + meta.config.maximumProfileImageSize + ']]'));
}
md5sum = crypto.createHash('md5');
md5sum.update(data.imageData);
md5sum = md5sum.digest('hex');
data.file = {
path: path.join(os.tmpdir(), md5sum)
};
var buffer = new Buffer(data.imageData.slice(data.imageData.indexOf('base64') + 7), 'base64');
fs.writeFile(data.file.path, buffer, {
encoding: 'base64'
}, next);
saveImageDataToTempFile(data.imageData, next);
},
function (next) {
var image = {
name: 'profileAvatar',
path: data.file.path,
uid: data.uid
};
function (path, next) {
image.path = path;
if (plugins.hasListeners('filter:uploadImage')) {
return plugins.fireHook('filter:uploadImage', {image: image, uid: data.uid}, next);
}
var filename = data.uid + '-profileavatar' + (keepAllVersions ? '-' + Date.now() : '');
async.waterfall([
function (next) {
file.isFileTypeAllowed(data.file.path, next);
},
function (next) {
file.saveFileToLocal(filename, 'profile', image.path, next);
},
function (upload, next) {
next(null, {
url: nconf.get('relative_path') + upload.url,
name: image.name
});
}
], next);
uploadProfileOrCover('profileavatar', image, data.imageData, next);
},
function (uploadData, next) {
url = uploadData.url;
User.setUserFields(data.uid, {uploadedpicture: url, picture: url}, next);
User.setUserFields(data.uid, {
uploadedpicture: url,
picture: url
}, next);
}
], function (err) {
deleteFile(image.path);
callback(err, {
url: url
});
});
};
function saveImageDataToTempFile(imageData, callback) {
var filename = crypto.createHash('md5').update(imageData).digest('hex');
var filepath = path.join(os.tmpdir(), filename);
var buffer = new Buffer(imageData.slice(imageData.indexOf('base64') + 7), 'base64');
fs.writeFile(filepath, buffer, {
encoding: 'base64'
}, function (err) {
callback(err, filepath);
});
}
function uploadProfileOrCover(type, image, imageData, callback) {
if (plugins.hasListeners('filter:uploadImage')) {
return plugins.fireHook('filter:uploadImage', {
image: image,
uid: image.uid
}, callback);
}
var filename = generateProfileImageFilename(image.uid, type, imageData);
saveFileToLocal(filename, image, callback);
}
function generateProfileImageFilename(uid, type, imageData) {
var extension = file.typeToExtension(imageData.slice(5, imageData.indexOf('base64') - 1));
var keepAllVersions = parseInt(meta.config['profile:keepAllUserImages'], 10) === 1;
var filename = uid + '-' + type + (keepAllVersions ? '-' + Date.now() : '') + (extension || '');
return filename;
}
function saveFileToLocal(filename, image, callback) {
async.waterfall([
function (next) {
file.isFileTypeAllowed(image.path, next);
},
function (next) {
fs.unlink(data.file.path, function (err) {
if (err) {
winston.error(err);
}
next();
file.saveFileToLocal(filename, 'profile', image.path, next);
},
function (upload, next) {
next(null, {
url: nconf.get('relative_path') + upload.url,
name: image.name
});
}
], function (err) {
if (err) {
callback(err); // send back the original error
}
], callback);
}
callback(err, {url: url});
});
};
function deleteFile(path) {
if (path) {
fs.unlink(path, function (err) {
if (err) {
winston.error(err);
}
});
}
}
User.removeCoverPicture = function (data, callback) {
db.deleteObjectFields('user:' + data.uid, ['cover:url', 'cover:position'], callback);

@ -1,2 +1,2 @@
--reporter dot
--timeout 15000
--timeout 25000

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save