diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-03-31 14:52:57 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-03-31 14:52:57 +0200 |
| commit | a7b2a2c8929ec1d17939f2527ac6033beeaea9b7 (patch) | |
| tree | c7e94a12caaf14a1d0ce8842f00590b07b381d20 | |
| parent | c3d17983b398b5c5b2c2c62dd8fff478b5f02b4d (diff) | |
ascii view
| -rw-r--r-- | lib/db/index.js | 6 | ||||
| -rw-r--r-- | lib/index.js | 7 | ||||
| -rw-r--r-- | public/assets/js/nav.js | 30 |
3 files changed, 33 insertions, 10 deletions
diff --git a/lib/db/index.js b/lib/db/index.js index b2ea59c..ffd8c27 100644 --- a/lib/db/index.js +++ b/lib/db/index.js @@ -4,7 +4,6 @@ var connection = require("./bookshelf") var bookshelf = connection.bookshelf var knex = connection.knex - /* MODELS */ var Image = db.Image = bookshelf.Model.extend({ @@ -30,6 +29,11 @@ db.getRandom = function () { qb.orderBy(knex.raw('RAND()')).limit(1) }).fetch() } +db.getRandomAscii = function () { + return ShaderImage.query(function(qb){ + qb.where("tag", "=", "ascii").orderBy(knex.raw('RAND()')).limit(1) + }).fetch() +} db.getIndex = function(limit, offset) { return Image.query(function(qb){ qb.orderBy("id", "desc").limit(limit) diff --git a/lib/index.js b/lib/index.js index 6d07dda..a9db423 100644 --- a/lib/index.js +++ b/lib/index.js @@ -78,6 +78,12 @@ site.init = function(){ }) }) + app.get("/p/get/randomascii", function(req, res){ + db.getRandomAscii().then(function(img){ + res.json(img) + }) + }) + /* shaderblaster / asciiblaster apis */ app.post("/cgi-bin/im/shader/upload", multer_upload.single('qqfile'), function(req, res){ var now = Math.floor(Date.now() / 1000) @@ -112,6 +118,7 @@ site.init = function(){ app.get("/p/:id", function(req, res){ res.sendFile("index.html", {root: './public'}) }) + app.use('/panke/', express.static(path.join(__dirname, '../public'))) app.use('/p/', express.static(path.join(__dirname, '../public'))) } diff --git a/public/assets/js/nav.js b/public/assets/js/nav.js index a53f6fb..b6be6b5 100644 --- a/public/assets/js/nav.js +++ b/public/assets/js/nav.js @@ -30,14 +30,11 @@ var NavView = View.extend({ return this.fetch(id) } } + if (window.location.pathname.indexOf("/panke/") !== -1) { + setInterval(() => { this.fetchAscii() }, 5000) + return this.fetchAscii() + } return this.latest() - - $(".prev").on("touchstart", function(){ - console.log("<<<<<PREV") - }) - $(".prev").on("click", function(){ - console.log("<<<<<CLICKPREV") - }) }, keydown: function(e){ @@ -84,15 +81,30 @@ var NavView = View.extend({ fetch: function(id){ this.fetching = true this.onLatest = false -console.log('fetch', id) + console.log('fetch', id) $.get("/p/get/" + id, function(data){ -console.log(data) + console.log(data) this.fetching = false this.display(data) history.pushState(data, document.title, "/p/" + data.id) }.bind(this)) }, + fetchAscii: function(){ + this.fetching = true + this.onLatest = false + console.log('fetch ascii') + $.get("/p/get/randomascii", function(data){ + console.log(data) + var asciiData = { + url: "https://s3.amazonaws.com/i.asdf.us/im/" + data.dir + "/" + data.newfile + } + this.fetching = false + this.display(data) + // history.pushState(data, document.title, "/p/" + data.id) + }.bind(this)) + }, + display: function(data){ if (! data || ! data.id) { this.onLatest = true |
