Browse Source

move to pug, some pagination stuff i guess

canon
Hazel Levine 2 years ago
parent
commit
3d53ebb748
11 changed files with 631 additions and 36 deletions
  1. +42
    -1
      app.js
  2. +7
    -0
      mixins/card.pug
  3. +480
    -5
      package-lock.json
  4. +2
    -1
      package.json
  5. +2
    -0
      public/index.css
  6. +4
    -5
      public/index.ejs
  7. +16
    -3
      public/index.js
  8. +39
    -0
      public/index.pug
  9. +12
    -0
      public/infinite-scroll.pkgd.min.js
  10. +10
    -21
      src/imagefile.js
  11. +17
    -0
      src/schema.js

+ 42
- 1
app.js View File

@ -1,17 +1,27 @@
// bunnydb app.js git 07/24/2018 hazel <arcetera@openmailbox.org>
const express = require('express');
const paginate = require('express-paginate');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const path = require('path');
const creds = require('./private/credentials');
const routes = require('./src/imagefile');
const schema = require('./src/schema')
const app = express();
// input your database url here
// mongodb://user:password@server:port/db
// TODO: put this in a seperate config?
const dbURL = `mongodb://${creds.mongoUser}:${creds.mongoPass}@localhost:27017/bunnies`;
mongoose.connect(dbURL);
app.use(paginate.middleware(15, 50)); // limit, maxLimit
app.use('/', routes);
app.use(express.static(__dirname + '/public'));
app.use(express.static(__dirname + '/public')); // allows access to /uploads/<image>
// DELETE: not needed i guess
app.get('/images', (req, res) => {
routes.getImages((err, genres) => {
if (err) {
@ -21,6 +31,7 @@ app.get('/images', (req, res) => {
});
});
// TODO: make this serve an actual page via ejs
app.get('/images/:id', (req, res) => {
routes.getImageById(req.params.id, (err, genres) => {
if (err) {
@ -36,6 +47,36 @@ app.get('/random', (req, res) => {
});
});
app.get('/pages/:page', async (req, res, next) => {
try {
const [ results, itemCount ] = await Promise.all([
schema.find({}).limit(req.query.limit).skip(req.skip).lean().exec(),
schema.count({})
]);
console.log(itemCount);
// const pageCount = Math.ceil(itemCount / req.query.limit);
const pageCount = Number(req.params.page); // TODO: additional checks on this
if (req.accepts('json')) {
res.json({
object: 'list',
has_more: paginate.hasNextPages(req)(pageCount),
data: results
});
} else {
res.render('pages', {
docs: results,
pageCount,
itemCount,
pages: paginate.getArrayPages(req)(3, pageCount, req.query.page)
});
}
} catch (err) {
next(err);
}
});
app.listen(3000, () => {
console.log('running on port 3000');
});

+ 7
- 0
mixins/card.pug View File

@ -0,0 +1,7 @@
// bunnydb card.pug CLIENT/git 07/30/2018 hazel <arcetera@openmailbox.org>
mixin card(path)
a(href=path)
.mdl-card.masonry-grid-item.mdl-shadow--2dp
figure.mdl-card__media
img(src=path, alt="")

+ 480
- 5
package-lock.json View File

@ -4,6 +4,19 @@
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@types/babel-types": {
"version": "7.0.4",
"resolved": "https://registry.npmjs.org/@types/babel-types/-/babel-types-7.0.4.tgz",
"integrity": "sha512-WiZhq3SVJHFRgRYLXvpf65XnV6ipVHhnNaNvE8yCimejrGglkg38kEj0JcizqwSHxmPSjcTlig/6JouxLGEhGw=="
},
"@types/babylon": {
"version": "6.16.3",
"resolved": "https://registry.npmjs.org/@types/babylon/-/babylon-6.16.3.tgz",
"integrity": "sha512-lyJ8sW1PbY3uwuvpOBZ9zMYKshMnQpXmeDHh8dj9j2nJm/xrW0FgB5gLSYOArj5X0IfaXnmhFoJnhS4KbqIMug==",
"requires": {
"@types/babel-types": "*"
}
},
"accepts": {
"version": "1.3.5",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.5.tgz",
@ -13,6 +26,36 @@
"negotiator": "0.6.1"
}
},
"acorn": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-3.3.0.tgz",
"integrity": "sha1-ReN/s56No/JbruP/U2niu18iAXo="
},
"acorn-globals": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/acorn-globals/-/acorn-globals-3.1.0.tgz",
"integrity": "sha1-/YJw9x+7SZawBPqIDuXUZXOnMb8=",
"requires": {
"acorn": "^4.0.4"
},
"dependencies": {
"acorn": {
"version": "4.0.13",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-4.0.13.tgz",
"integrity": "sha1-EFSVrlNh1pe9GVyCUZLhrX8lN4c="
}
}
},
"align-text": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/align-text/-/align-text-0.1.4.tgz",
"integrity": "sha1-DNkKVhCT810KmSVsIrcGlDP60Rc=",
"requires": {
"kind-of": "^3.0.2",
"longest": "^1.0.1",
"repeat-string": "^1.5.2"
}
},
"append-field": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/append-field/-/append-field-0.1.0.tgz",
@ -23,6 +66,11 @@
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
"integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
},
"asap": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz",
"integrity": "sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY="
},
"async": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/async/-/async-2.6.1.tgz",
@ -31,6 +79,31 @@
"lodash": "^4.17.10"
}
},
"babel-runtime": {
"version": "6.26.0",
"resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz",
"integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=",
"requires": {
"core-js": "^2.4.0",
"regenerator-runtime": "^0.11.0"
}
},
"babel-types": {
"version": "6.26.0",
"resolved": "https://registry.npmjs.org/babel-types/-/babel-types-6.26.0.tgz",
"integrity": "sha1-o7Bz+Uq0nrb6Vc1lInozQ4BjJJc=",
"requires": {
"babel-runtime": "^6.26.0",
"esutils": "^2.0.2",
"lodash": "^4.17.4",
"to-fast-properties": "^1.0.3"
}
},
"babylon": {
"version": "6.18.0",
"resolved": "https://registry.npmjs.org/babylon/-/babylon-6.18.0.tgz",
"integrity": "sha512-q/UEjfGJ2Cm3oKV71DJz9d25TPnq5rhBVL2Q4fA5wcC3jcrdn7+SssEybFIxwAvvP+YCsCYNKughoF33GxgycQ=="
},
"bluebird": {
"version": "3.5.0",
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.0.tgz",
@ -77,6 +150,46 @@
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz",
"integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg="
},
"camelcase": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-1.2.1.tgz",
"integrity": "sha1-m7UwTS4LVmmLLHWLCKPqqdqlijk="
},
"center-align": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/center-align/-/center-align-0.1.3.tgz",
"integrity": "sha1-qg0yYptu6XIgBBHL1EYckHvCt60=",
"requires": {
"align-text": "^0.1.3",
"lazy-cache": "^1.0.3"
}
},
"character-parser": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/character-parser/-/character-parser-2.2.0.tgz",
"integrity": "sha1-x84o821LzZdE5f/CxfzeHHMmH8A=",
"requires": {
"is-regex": "^1.0.3"
}
},
"clean-css": {
"version": "4.1.11",
"resolved": "https://registry.npmjs.org/clean-css/-/clean-css-4.1.11.tgz",
"integrity": "sha1-Ls3xRaujj1R0DybO/Q/z4D4SXWo=",
"requires": {
"source-map": "0.5.x"
}
},
"cliui": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/cliui/-/cliui-2.1.0.tgz",
"integrity": "sha1-S0dXYP+AJkx2LDoXGQMukcf+oNE=",
"requires": {
"center-align": "^0.1.1",
"right-align": "^0.1.1",
"wordwrap": "0.0.2"
}
},
"concat-stream": {
"version": "1.6.2",
"resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz",
@ -117,6 +230,17 @@
}
}
},
"constantinople": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/constantinople/-/constantinople-3.1.2.tgz",
"integrity": "sha512-yePcBqEFhLOqSBtwYOGGS1exHo/s1xjekXiinh4itpNQGCu4KA1euPh1fg07N2wMITZXQkBz75Ntdt1ctGZouw==",
"requires": {
"@types/babel-types": "^7.0.0",
"@types/babylon": "^6.16.2",
"babel-types": "^6.26.0",
"babylon": "^6.18.0"
}
},
"content-disposition": {
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz",
@ -137,6 +261,11 @@
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
"integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw="
},
"core-js": {
"version": "2.5.7",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.7.tgz",
"integrity": "sha512-RszJCAxg/PP6uzXVXL6BsxSXx/B05oJAQ2vkJRjyjrEcNVycaqOmNb5OTxZPE3xa5gwZduqza6L9JOCenh/Ecw=="
},
"core-util-is": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
@ -150,6 +279,11 @@
"ms": "2.0.0"
}
},
"decamelize": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz",
"integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA="
},
"depd": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
@ -169,16 +303,16 @@
"streamsearch": "0.1.2"
}
},
"doctypes": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/doctypes/-/doctypes-1.1.0.tgz",
"integrity": "sha1-6oCxBqh1OHdOijpKWv4pPeSJ4Kk="
},
"ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
},
"ejs": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/ejs/-/ejs-2.6.1.tgz",
"integrity": "sha512-0xy4A/twfrRCnkhfk8ErDi5DqdAsAqeGxht4xkCUrsvhhbQNs7E+4jV0CN7+NKIY0aHE72+XvqtBIXzD31ZbXQ=="
},
"encodeurl": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
@ -189,6 +323,11 @@
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
"integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg="
},
"esutils": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz",
"integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs="
},
"etag": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
@ -299,6 +438,17 @@
}
}
},
"express-paginate": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/express-paginate/-/express-paginate-1.0.0.tgz",
"integrity": "sha512-M4+ee9YdcRoBltBYBwMcZUH589KeoVy62dBTyaZXlrggnJFGvk3Rgw0XYdL2PXN0BQROrnYskw+QxtoPsdY+AQ==",
"requires": {
"lodash.assign": "^4.2.0",
"lodash.clone": "^4.5.0",
"lodash.isobject": "^3.0.2",
"qs": "^6.5.1"
}
},
"finalhandler": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.1.tgz",
@ -330,6 +480,19 @@
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
"integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac="
},
"function-bind": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
},
"has": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
"integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==",
"requires": {
"function-bind": "^1.1.1"
}
},
"http-errors": {
"version": "1.6.3",
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz",
@ -359,26 +522,112 @@
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.6.0.tgz",
"integrity": "sha1-4/o1e3c9phnybpXwSdBVxyeW+Gs="
},
"is-buffer": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w=="
},
"is-expression": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/is-expression/-/is-expression-3.0.0.tgz",
"integrity": "sha1-Oayqa+f9HzRx3ELHQW5hwkMXrJ8=",
"requires": {
"acorn": "~4.0.2",
"object-assign": "^4.0.1"
},
"dependencies": {
"acorn": {
"version": "4.0.13",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-4.0.13.tgz",
"integrity": "sha1-EFSVrlNh1pe9GVyCUZLhrX8lN4c="
},
"object-assign": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM="
}
}
},
"is-promise": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz",
"integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o="
},
"is-regex": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.0.4.tgz",
"integrity": "sha1-VRdIm1RwkbCTDglWVM7SXul+lJE=",
"requires": {
"has": "^1.0.1"
}
},
"isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
},
"js-stringify": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/js-stringify/-/js-stringify-1.0.2.tgz",
"integrity": "sha1-Fzb939lyTyijaCrcYjCufk6Weds="
},
"jstransformer": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/jstransformer/-/jstransformer-1.0.0.tgz",
"integrity": "sha1-7Yvwkh4vPx7U1cGkT2hwntJHIsM=",
"requires": {
"is-promise": "^2.0.0",
"promise": "^7.0.1"
}
},
"kareem": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/kareem/-/kareem-2.2.1.tgz",
"integrity": "sha512-xpDFy8OxkFM+vK6pXy6JmH92ibeEFUuDWzas5M9L7MzVmHW3jzwAHxodCPV/BYkf4A31bVDLyonrMfp9RXb/oA=="
},
"kind-of": {
"version": "3.2.2",
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz",
"integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=",
"requires": {
"is-buffer": "^1.1.5"
}
},
"lazy-cache": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/lazy-cache/-/lazy-cache-1.0.4.tgz",
"integrity": "sha1-odePw6UEdMuAhF07O24dpJpEbo4="
},
"lodash": {
"version": "4.17.10",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz",
"integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg=="
},
"lodash.assign": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/lodash.assign/-/lodash.assign-4.2.0.tgz",
"integrity": "sha1-DZnzzNem0mHRm9rrkkUAXShYCOc="
},
"lodash.clone": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/lodash.clone/-/lodash.clone-4.5.0.tgz",
"integrity": "sha1-GVhwRQ9aExkkeN9Lw9I9LeoZB7Y="
},
"lodash.get": {
"version": "4.4.2",
"resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz",
"integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk="
},
"lodash.isobject": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/lodash.isobject/-/lodash.isobject-3.0.2.tgz",
"integrity": "sha1-PI+41bW/S/kK4G4U8qUwpO2TXh0="
},
"longest": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz",
"integrity": "sha1-MKCy2jj3N3DoKUoNIuZiXtd9AJc="
},
"media-typer": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
@ -542,6 +791,11 @@
"util": "^0.10.3"
}
},
"path-parse": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.5.tgz",
"integrity": "sha1-PBrfhx6pzWyUMbbqK9dKD/BVxME="
},
"path-to-regexp": {
"version": "0.1.7",
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
@ -557,6 +811,14 @@
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz",
"integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw=="
},
"promise": {
"version": "7.3.1",
"resolved": "https://registry.npmjs.org/promise/-/promise-7.3.1.tgz",
"integrity": "sha512-nolQXZ/4L+bP/UGlkfaIujX9BKxGwmQ9OT4mOt5yvy8iK1h3wqTEJCijzGANTCCl9nWjY41juyAn2K3Q1hLLTg==",
"requires": {
"asap": "~2.0.3"
}
},
"proxy-addr": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.3.tgz",
@ -566,6 +828,127 @@
"ipaddr.js": "1.6.0"
}
},
"pug": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/pug/-/pug-2.0.3.tgz",
"integrity": "sha1-ccuoJTfJWl6rftBGluQiH1Oqh44=",
"requires": {
"pug-code-gen": "^2.0.1",
"pug-filters": "^3.1.0",
"pug-lexer": "^4.0.0",
"pug-linker": "^3.0.5",
"pug-load": "^2.0.11",
"pug-parser": "^5.0.0",
"pug-runtime": "^2.0.4",
"pug-strip-comments": "^1.0.3"
}
},
"pug-attrs": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/pug-attrs/-/pug-attrs-2.0.3.tgz",
"integrity": "sha1-owlflw5kFR972tlX7vVftdeQXRU=",
"requires": {
"constantinople": "^3.0.1",
"js-stringify": "^1.0.1",
"pug-runtime": "^2.0.4"
}
},
"pug-code-gen": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/pug-code-gen/-/pug-code-gen-2.0.1.tgz",
"integrity": "sha1-CVHsgyJddNjPxHan+Zolm199BQw=",
"requires": {
"constantinople": "^3.0.1",
"doctypes": "^1.1.0",
"js-stringify": "^1.0.1",
"pug-attrs": "^2.0.3",
"pug-error": "^1.3.2",
"pug-runtime": "^2.0.4",
"void-elements": "^2.0.1",
"with": "^5.0.0"
}
},
"pug-error": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/pug-error/-/pug-error-1.3.2.tgz",
"integrity": "sha1-U659nSm7A89WRJOgJhCfVMR/XyY="
},
"pug-filters": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/pug-filters/-/pug-filters-3.1.0.tgz",
"integrity": "sha1-JxZVVbwEwjbkqisDZiRt+gIbYm4=",
"requires": {
"clean-css": "^4.1.11",
"constantinople": "^3.0.1",
"jstransformer": "1.0.0",
"pug-error": "^1.3.2",
"pug-walk": "^1.1.7",
"resolve": "^1.1.6",
"uglify-js": "^2.6.1"
}
},
"pug-lexer": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/pug-lexer/-/pug-lexer-4.0.0.tgz",
"integrity": "sha1-IQwYRX7y4XYCQnQMXmR715TOwng=",
"requires": {
"character-parser": "^2.1.1",
"is-expression": "^3.0.0",
"pug-error": "^1.3.2"
}
},
"pug-linker": {
"version": "3.0.5",
"resolved": "https://registry.npmjs.org/pug-linker/-/pug-linker-3.0.5.tgz",
"integrity": "sha1-npp65ABWgtAn3uuWsAD4juuDoC8=",
"requires": {
"pug-error": "^1.3.2",
"pug-walk": "^1.1.7"
}
},
"pug-load": {
"version": "2.0.11",
"resolved": "https://registry.npmjs.org/pug-load/-/pug-load-2.0.11.tgz",
"integrity": "sha1-5kjlftET/iwfRdV4WOorrWvAFSc=",
"requires": {
"object-assign": "^4.1.0",
"pug-walk": "^1.1.7"
},
"dependencies": {
"object-assign": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM="
}
}
},
"pug-parser": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/pug-parser/-/pug-parser-5.0.0.tgz",
"integrity": "sha1-45Stmz/KkxI5QK/4hcBuRKt+aOQ=",
"requires": {
"pug-error": "^1.3.2",
"token-stream": "0.0.1"
}
},
"pug-runtime": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/pug-runtime/-/pug-runtime-2.0.4.tgz",
"integrity": "sha1-4XjhvaaKsujArPybztLFT9iM61g="
},
"pug-strip-comments": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/pug-strip-comments/-/pug-strip-comments-1.0.3.tgz",
"integrity": "sha1-8VWVkiBu3G+FMQ2s9K+0igJa9Z8=",
"requires": {
"pug-error": "^1.3.2"
}
},
"pug-walk": {
"version": "1.1.7",
"resolved": "https://registry.npmjs.org/pug-walk/-/pug-walk-1.1.7.tgz",
"integrity": "sha1-wA1cUSi6xYBr7BXSt+fNq+QlMfM="
},
"qs": {
"version": "6.5.2",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz",
@ -598,11 +981,21 @@
"string_decoder": "~0.10.x"
}
},
"regenerator-runtime": {
"version": "0.11.1",
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz",
"integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg=="
},
"regexp-clone": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/regexp-clone/-/regexp-clone-0.0.1.tgz",
"integrity": "sha1-p8LgmJH9vzj7sQ03b7cwA+aKxYk="
},
"repeat-string": {
"version": "1.6.1",
"resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz",
"integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc="
},
"require_optional": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/require_optional/-/require_optional-1.0.1.tgz",
@ -612,11 +1005,27 @@
"semver": "^5.1.0"
}
},
"resolve": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.8.1.tgz",
"integrity": "sha512-AicPrAC7Qu1JxPCZ9ZgCZlY35QgFnNqc+0LtbRNxnVw4TXvjQ72wnuL9JQcEBgXkI9JM8MsT9kaQoHcpCRJOYA==",
"requires": {
"path-parse": "^1.0.5"
}
},
"resolve-from": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-2.0.0.tgz",
"integrity": "sha1-lICrIOlP+h2egKgEx+oUdhGWa1c="
},
"right-align": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/right-align/-/right-align-0.1.3.tgz",
"integrity": "sha1-YTObci/mo1FWiSENJOFMlhSGE+8=",
"requires": {
"align-text": "^0.1.1"
}
},
"safe-buffer": {
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz",
@ -686,6 +1095,11 @@
"resolved": "https://registry.npmjs.org/sliced/-/sliced-1.0.1.tgz",
"integrity": "sha1-CzpmK10Ewxd7GSa+qCsD+Dei70E="
},
"source-map": {
"version": "0.5.7",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz",
"integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w="
},
"statuses": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
@ -701,6 +1115,16 @@
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ="
},
"to-fast-properties": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-1.0.3.tgz",
"integrity": "sha1-uDVx+k2MJbguIxsG46MFXeTKGkc="
},
"token-stream": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/token-stream/-/token-stream-0.0.1.tgz",
"integrity": "sha1-zu78cXp2xDFvEm0LnbqlXX598Bo="
},
"type-is": {
"version": "1.6.16",
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.16.tgz",
@ -715,6 +1139,22 @@
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
"integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c="
},
"uglify-js": {
"version": "2.8.29",
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-2.8.29.tgz",
"integrity": "sha1-KcVzMUgFe7Th913zW3qcty5qWd0=",
"requires": {
"source-map": "~0.5.1",
"uglify-to-browserify": "~1.0.0",
"yargs": "~3.10.0"
}
},
"uglify-to-browserify": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz",
"integrity": "sha1-bgkk1r2mta/jSeOabWMoUKD4grc=",
"optional": true
},
"unpipe": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
@ -748,10 +1188,45 @@
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
"integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw="
},
"void-elements": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/void-elements/-/void-elements-2.0.1.tgz",
"integrity": "sha1-wGavtYK7HLQSjWDqkjkulNXp2+w="
},
"window-size": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/window-size/-/window-size-0.1.0.tgz",
"integrity": "sha1-VDjNLqk7IC76Ohn+iIeu58lPnJ0="
},
"with": {
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/with/-/with-5.1.1.tgz",
"integrity": "sha1-+k2qktrzLE6pTtRTyB8EaGtXXf4=",
"requires": {
"acorn": "^3.1.0",
"acorn-globals": "^3.0.0"
}
},
"wordwrap": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.2.tgz",
"integrity": "sha1-t5Zpu0LstAn4PVg8rVLKF+qhZD8="
},
"xtend": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz",
"integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68="
},
"yargs": {
"version": "3.10.0",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-3.10.0.tgz",
"integrity": "sha1-9+572FfdfB0tOMDnTvvWgdFDH9E=",
"requires": {
"camelcase": "^1.0.2",
"cliui": "^2.1.0",
"decamelize": "^1.0.0",
"window-size": "0.1.0"
}
}
}
}

+ 2
- 1
package.json View File

@ -25,11 +25,12 @@
"homepage": "https://github.com/ix/bunnydb#readme",
"dependencies": {
"body-parser": "^1.18.3",
"ejs": "^2.6.1",
"express": "^4.16.3",
"express-paginate": "^1.0.0",
"mongoose": "^5.2.5",
"multer": "^1.3.1",
"path": "^0.12.7",
"pug": "^2.0.3",
"uuid": "^3.3.2"
}
}

+ 2
- 0
public/index.css View File

@ -1,3 +1,5 @@
/* bunnydb index.css CLIENT/git 07/26/2018 hazel <arcetera@openmailbox.org> */
.masonry-grid {
max-width: auto;
margin: 0 auto;


+ 4
- 5
public/index.ejs View File

@ -1,3 +1,5 @@
<!-- bunnydb index.ejs CLIENT/git 07/24/2018 hazel <arcetera@openmailbox.org> -->
<html>
<head>
<title>test db</title>
@ -7,6 +9,7 @@
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
<script src="masonry.pkgd.min.js"></script>
<script src="imagesloaded.pkgd.min.js"></script>
<script src="infinite-scroll.pkgd.min.js"></script>
<script src="index.js"></script>
</head>
<body onload="loaded()">
@ -25,7 +28,7 @@
<main class="mdl-layout__content">
<section class="mdl-layout__tab-panel is-active" id="fixed-tab-1">
<div class="page-content">
<div class="masonry-grid">
<div class="masonry-grid are-images-unloaded">
<% files.forEach((bun) => { %>
<a href=<%= bun.path.replace("public/", "") %>>
<div class="mdl-card masonry-grid-item mdl-shadow--2dp">
@ -40,10 +43,6 @@
</section>
<section class="mdl-layout__tab-panel" id="fixed-tab-2">
<div class="page-content">
<!--<form id="file-catcher" action="/" method="POST" enctype="multipart/form-data">
<input id="file-input" type="file" name="myimage" multiple />
<input type="submit" name="submit" value="submit" />
</form> -->
<form id="file-catcher">
<input id="file-input" type="file" multiple />
<button type="submit">


+ 16
- 3
public/index.js View File

@ -1,15 +1,28 @@
function loaded() {
// bunnydb index.js CLIENT/git 07/28/2018 hazel <arcetera@openmailbox.org>
window.onload = () => {
let elem = document.querySelector('.masonry-grid');
let msnry = new Masonry(elem, {
itemSelector: '.masonry-grid-item',
itemSelector: '.masonry-grid-item', // select none at first
gutter: 16,
fitWidth: true
fitWidth: true,
/* visibleStyle: { transform: 'translateY(0)', opacity: 1 },
hiddenStyle: { transform: 'translateY(100px)', opacity: 0 } */
});
imagesLoaded(elem).on('progress', () => {
/* elem.classList.remove('are-images-unloaded'); msnry.options.itemSelector = '.masonry-grid-item';
let items = elem.querySelectorAll('.masonry-grid-item');
msnry.appended(items); */
msnry.layout();
});
/* let infScroll = new InfiniteScroll(elem, {
append: '.masonry-grid-item',
outlayer: msnry,
status: '.page-load-status'
}); */
let fileList = [];
let fileCatcher = document.getElementById('file-catcher');
let fileInput = document.getElementById('file-input');


+ 39
- 0
public/index.pug View File

@ -0,0 +1,39 @@
//- bunnydb index.pug CLIENT/git 07/30/2018 hazel <arcetera@openmailbox.org>
doctype html
include ../mixins/card.pug
html
head
title Bunny DB
link(rel='stylesheet', href='index.css')
link(rel='stylesheet', href='https://fonts.googleapis.com/icon?family=Material+Icons')
link(rel='stylesheet', href='https://code.getmdl.io/1.3.0/material.indigo-pink.min.css')
script(defer, src='https://code.getmdl.io/1.3.0/material.min.js')
script(src='masonry.pkgd.min.js')
script(src='imagesloaded.pkgd.min.js')
script(src='infinite-scroll.pkgd.min.js')
script(src='index.js')
.mdl-layout.mdl-js-layout.mdl-layout--fixed-header.mdl-layout--fixed-tabs
header.mdl-layout__header
.mdl-layout__header-row
span.mdl-layout--title Bunny DB
.mdl-layout__tab-bar.mdl-js-ripple-effect
a(href='#fixed-tab-1').mdl-layout__tab.is-active Browse
a(href='#fixed-tab-2').mdl-layout__tab Submit
a(href='#fixed-tab-3').mdl-layout__tab About
main.mdl-layout__content
section#fixed-tab-1.mdl-layout__tab-panel.is-active
.page-content
.masonry-grid
each bun in files
+card(bun.path.replace('public/', ''))
section#fixed-tab-2.mdl-layout__tab-panel
.page-content
form#file-catcher
input(type='file', multiple)#file-input
button(type='submit')
| Submit
section#fixed-tab-3.mdl-layout__tab-panel
.page-content

+ 12
- 0
public/infinite-scroll.pkgd.min.js
File diff suppressed because it is too large
View File


+ 10
- 21
src/imagefile.js View File

@ -1,29 +1,18 @@
// bunnydb imagefile.js git 07/24/2018 hazel <arcetera@openmailbox.org>
const express = require('express');
const multer = require('multer');
const mongoose = require('mongoose');
const uuid = require('uuid/v4');
const path = require('path');
const fs = require('fs');
const schema = require('./schema');
let router = express.Router();
const imageSchema = mongoose.Schema({
path: {
type: String,
required: true,
trim: true
},
originalname: {
type: String,
required: true
}
});
const Image = module.exports = mongoose.model('files', imageSchema);
function getAllFiles(collection, cb) {
let files = [];
collection.find({}, (err, buns) => {
collection.find({}, (err, buns) => {
files = buns;
cb(files);
});
@ -34,20 +23,20 @@ function stripPath(dir) {
}
router.getImages = (callback, limit) => {
Image.find(callback).limit(limit);
schema.find(callback).limit(limit);
}
router.getImageById = (id, callback) => {
Image.findById(id, callback);
schema.findById(id, callback);
}
router.addImage = (image, callback) => {
Image.create(image, callback);
schema.create(image, callback);
}
router.getImageRandom = (callback) => {
let file = '';
getAllFiles(Image, (filesOut) => {
getAllFiles(schema, (filesOut) => {
file = filesOut[Math.floor(Math.random()*filesOut.length)];
callback(file.path.replace('public/', ''));
});
@ -67,8 +56,8 @@ let upload = multer({
});
router.get('/', (req, res, next) => {
getAllFiles(Image, (filesOut) => {
res.render('../public/index.ejs', {
getAllFiles(schema, (filesOut) => {
res.render('../public/index.pug', {
files: filesOut,
stripBun: stripPath
});


+ 17
- 0
src/schema.js View File

@ -0,0 +1,17 @@
// bunnydb schema.js git 07/30/2018 hazel <arcetera@openmailbox.org>
const mongoose = require('mongoose');
const imageSchema = mongoose.Schema({
path: {
type: String,
required: true,
trim: true
},
originalname: {
type: String,
required: true
}
});
const Image = module.exports = mongoose.model('files', imageSchema);

Loading…
Cancel
Save