-
Notifications
You must be signed in to change notification settings - Fork 1
/
filter_images.coffee
54 lines (43 loc) · 1.22 KB
/
filter_images.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
_ = require 'underscore'
HTTP = require 'http'
URL = require 'url'
IM = require 'imagemagick'
FS = require 'fs'
Mongoose = require 'mongoose'
publicPath = __dirname + '/public'
Schema = Mongoose.Schema
ObjectId = Schema.ObjectId
placeSchema = new Schema {
name: { type: String, required: true },
description: { type: String },
coord: { type: [Number], index: '2dsphere', required: true },
kind: { type: String },
address: {
city: { type: String },
street: { type: String },
house: { type: String }
},
images: [{
url: { type: String },
ext: { type: String }
}],
owner: { type: ObjectId, ref: 'User' }
tags: [{ type: ObjectId, ref: 'Tag' }]
}
Place = Mongoose.model 'Place', placeSchema
Mongoose.connect 'mongodb://localhost/travel_foot', (err) ->
throw err if err
Place.find (err, places) ->
throw err if err
c = 0
for place in places
c += 1
images = _.filter place.images, (image) ->
FS.existsSync("#{publicPath}/#{image.url}.#{image.ext}")
place.images = images
place.save (err) ->
throw err if err
c -= 1
if c == 0
Mongoose.connection.close()
console.log "done"