This repository has been archived by the owner on Oct 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolve issues with duplicate files, separate buckets, etc, rework so…
…me indexes, add some more tests
- Loading branch information
Gordon Hall
committed
Mar 15, 2016
1 parent
a880ba8
commit 75e75f9
Showing
8 changed files
with
313 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict'; | ||
|
||
const mongoose = require('mongoose'); | ||
const mimetypes = require('mime-db'); | ||
const SchemaOptions = require('../options'); | ||
|
||
/** | ||
* Represents a bucket entry that points to a file | ||
* @constructor | ||
*/ | ||
var BucketEntry = new mongoose.Schema({ | ||
file: { | ||
type: String, | ||
ref: 'File' | ||
}, | ||
bucket: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: 'Bucket' | ||
}, | ||
mimetype: { | ||
type: String, | ||
enum: Object.keys(mimetypes), | ||
default: 'application/octet-stream', | ||
required: true | ||
}, | ||
name: { | ||
type: String | ||
} | ||
}); | ||
|
||
BucketEntry.virtual('filename').get(function() { | ||
return this.name || this.file; | ||
}); | ||
|
||
BucketEntry.index({ file: 1, bucket: 1 }, { unique: true }); | ||
|
||
BucketEntry.plugin(SchemaOptions, { | ||
read: 'secondaryPreferred' | ||
}); | ||
|
||
BucketEntry.set('toObject', { | ||
virtuals: true, | ||
transform: function(doc, ret) { | ||
delete ret.__v; | ||
delete ret._id; | ||
} | ||
}); | ||
|
||
module.exports = function(connection) { | ||
return connection.model('BucketEntry', BucketEntry); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.