-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added image upload support for NeoCities with a local storage as a ba…
…ckup.
- Loading branch information
Glitch (glitch-fediverse-bot)
committed
Oct 4, 2018
1 parent
4e87f14
commit 7c7f4f2
Showing
26 changed files
with
300 additions
and
103 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
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,14 @@ | ||
 | ||
|
||
# Generative art bot | ||
|
||
This is an example of a bot that generates images. It uses an image generator from [generative-art-bot](https://glitch.com/edit/#!/generative-art-bot). | ||
|
||
(Note that the code needed to be slightly modified to work with this project.) | ||
|
||
To try this example, copy the content of `examples/generative-art-bot/routes/bot-endpoint.js` to `routes/bot-endpoint.js` file and run your bot using its endpoint. | ||
|
||
By default, the images are stored in the `.data/img` folder. Glitch only provides ~128MB of storage (there are technical limitations to using the `assets` folder, which gives you additional ~500MB), but you can upload your images to NeoCities, which comes with a free 1GB of space, and has a paid plan ([$5/month](https://neocities.org/supporter)) that offers 50GB. | ||
|
||
Simply sign up for an account at [neocities.org](https://neocities.org/), and save your login information to the `.env` file as `NEOCITIES_USERNAME` and `NEOCITIES_PASSWORD`. | ||
|
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,57 @@ | ||
var express = require('express'), | ||
router = express.Router(), | ||
ColorScheme = require('color-scheme'), | ||
generators = { | ||
triangular_mesh: require(__dirname + '/../generators/triangular-mesh.js') | ||
}, | ||
grammar = require(__dirname + '/../tracery/tracery.js').grammar, | ||
helpers = require(__dirname + '/../helpers/general.js'), | ||
image_uploader = require(__dirname + '/../helpers/image-uploader.js'), | ||
bot = require(__dirname + '/../bot.js'); | ||
|
||
router.get('/', function (req, res) { | ||
var content = grammar.flatten("#origin#"), | ||
scheme = new ColorScheme; | ||
|
||
/* | ||
See https://www.npmjs.com/package/color-scheme#schemes on how to use ColorScheme. | ||
*/ | ||
|
||
scheme.from_hex(helpers.get_random_hex().replace('#','')) | ||
.scheme('mono') | ||
.variation('hard'); | ||
|
||
generators.triangular_mesh({ | ||
width: 800, | ||
height: 360, | ||
colors: scheme.colors() | ||
}, function(err, img_data){ | ||
// console.log({img_url: `${bot.bot_url}/${img_data.path}`}); | ||
|
||
var img_name = img_data.path.replace('img/', ''); | ||
|
||
image_uploader.upload_image(img_data, function(err, img_url, data){ | ||
if (err){ | ||
console.log(err); | ||
} else { | ||
// console.log(img_url); | ||
|
||
bot.create_post({ | ||
type: 'Note', | ||
content: content, | ||
attachment: [ | ||
{ | ||
url: img_url, | ||
content: content // Image description here. | ||
} | ||
] | ||
}, function(err, message){ | ||
res.setHeader('Content-Type', 'application/json'); | ||
res.send(JSON.stringify(message)); | ||
}); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
module.exports = router; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.