Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an optional category to be inserted into the path #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/attachments.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ var plugin = function(schema, options) {
// path: String(required). Path to the file in the file system.
// name: String(optional). Original Name of the file.
// mime: String(optional). Mime type of the file.
// category: String(optional). A top-level grouping for the files.
schema.methods.attach = function(propertyName, attachmentInfo, cb) {
var selfModel = this;
if(propertyNames.indexOf(propertyName) == -1) return cb(new Error('property "' + propertyName + '" was not registered as an attachment property'));
Expand Down Expand Up @@ -168,7 +169,12 @@ var plugin = function(schema, options) {
var finishConversion = function(styleFilePath, atts, cb) {
var ext = path.extname(styleFilePath);
var filenameId = options.filenameId ? selfModel[options.filenameId] : selfModel.id;
var storageStylePath = '/' + options.directory + '/' + filenameId + '-' + styleName + ext;
var storageStylePath;
if(attachmentInfo.category) {
storageStylePath = '/' + options.directory + '/' + attachmentInfo.category + '/' + filenameId + '-' + styleName + ext;
} else {
storageStylePath = '/' + options.directory + '/' + filenameId + '-' + styleName + ext;
}
fs.stat(styleFilePath, function(err, stats) {
if(err) return cb(err);
cb(null, {
Expand Down