{"id":16812192,"url":"https://github.com/flet/revisit-mutagen","last_synced_at":"2025-04-05T09:23:38.514Z","repository":{"id":20176742,"uuid":"23447652","full_name":"Flet/revisit-mutagen","owner":"Flet","description":"A hapi plugin to easily expose a http://revisit.link glitch as a service that adheres to http://revisit.link/spec.html","archived":false,"fork":false,"pushed_at":"2015-12-04T19:49:58.000Z","size":1126,"stargazers_count":1,"open_issues_count":8,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-03T12:54:37.665Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Flet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-29T00:41:00.000Z","updated_at":"2016-01-14T16:31:18.000Z","dependencies_parsed_at":"2022-08-21T17:01:04.061Z","dependency_job_id":null,"html_url":"https://github.com/Flet/revisit-mutagen","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flet%2Frevisit-mutagen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flet%2Frevisit-mutagen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flet%2Frevisit-mutagen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flet%2Frevisit-mutagen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Flet","download_url":"https://codeload.github.com/Flet/revisit-mutagen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247313660,"owners_count":20918673,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T10:21:00.864Z","updated_at":"2025-04-05T09:23:38.489Z","avatar_url":"https://github.com/Flet.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"revisit-mutagen\n===============\n\nA hapi plugin to easily expose a http://revisit.link mutation as a service that adheres to http://revisit.link/spec.html\n\nThis can be used to quickly spin up a server to serve\n\n\nthe plugin options is expected to be an object with the key representing the base\npath and the value being the 'mutator' function/module. Pass in one or many of these!\nSome example mutator npm modules: butts-gm, trippyshift\n\n```javascript\nvar options = {\n    glitches: {\n        trippyshift: require('trippyshift'),\n        butts: require('butts-gm'),\n        mylittlemutant: function(buffer, callback) {\n            //awesome goes here\n            callback(null, someMutatedbuffer);\n        }\n    }\n};\n```\n\nThe mutator should be a function that takes a buffer and a callback. It\nshould then execute the callback with a buffer as the second argument\nor an error as the first argument.\n\nAdditional Options\n------------------\n* **maxDataSize** (number) - set the max size of data that can be POSTed to the service. Default 2000000 (2MB).\n* **sampleGif** (string) - file path to a gif image to override the default sample.gif. Note that the guideline is a 60x60 image for samples on the hub.\n* **sampleJpg** (string) - file path to a gif image to override the default sample.jpg\n* **moreSamples** (array of strings) - array of file paths to additional images to expose as GET urls. The url will be derived from the file name: /myglitch/**pug.gif**. Be sure that your custom file names will not conflict with existing paths (i.e. don't name them sample.jpg or sample.gif)\n\nHere is an example options object with all these options enabled:\n\n```javascript\nvar options = {\n    maxDataSize: 1000000,\n    sampleGif: './waybettersample.gif',\n    sampleJpg: './anothersample.jpg',\n    moreSamples: ['./pug.gif', './face.jpg'],\n    glitches: {\n        myglitch: function(buffer, callback) {\n            //awesome goes here\n            callback(null, someMutatedbuffer);\n        }\n    }\n};\n```\n\nFull example Server\n-------------------\nFollow the instructions below to create a new hapi server using this plugin. This also shows how to create a simple glitch using `glitcher`.\n\nYou can also just go and take a look at or clone [my personal version](https://github.com/Flet/technodrome).\n\n\n\n1) Make a new directory, create a package.json and install some modules:\n```\nmkdir myserver\ncd myserver\nnpm init\n\u003c\u003cfill things in, press enter a lot\u003e\u003e\nnpm install --save hapi revisit-mutagen readimage glitcher writegif\n```\n\n2) create **index.js** in that directory with this content:\n\n```javascript\nvar Hapi = require('hapi'),\n    server = Hapi.createServer('0.0.0.0', process.env.PORT || 8080);\n\nserver.pack.register({\n    plugin: require('revisit-mutagen'),\n    options: {\n        glitches: {\n            myglitch: function(buffer, callback) {\n                // you can just write your own glitch inline or require() it in...\n\n                var readimage = require('readimage'),\n                    glitcher = require('glitcher'),\n                    gifWriter = require('writegif');\n\n                readimage(buffer, function(err, image) {\n                    if (err) {\n                        return callback(err);\n                    }\n\n                    if (image.frames.length == 1) {\n                        glitcher.rainbowClamp(image.frames[0].data);\n                    } else {\n                        glitcher.rainbow(image.frames);\n                    }\n\n                    gifWriter(image, function(err, finalgif) {\n                        return callback(null, finalgif);\n                    });\n\n                });\n            }\n        }\n    }\n}, function(err) {\n    if (err) throw err;\n    server.start(function() {\n\n        // list out all the routes for verification\n        server.table().forEach(function(row) {\n            console.log(server.info.uri + row.path + \" (\" + row.method + \")\");\n        });\n\n        console.log(\"Hapi server started @\", server.info.uri);\n    });\n\n});\n```\n\n3) Start the server up and check the output:\n```\nnpm start\n\n...\n\nhttp://0.0.0.0:8080/{anything?} (head)\nhttp://0.0.0.0:8080/myglitch/sample.gif (get)\nhttp://0.0.0.0:8080/myglitch/sample.jpg (get)\nhttp://0.0.0.0:8080/myglitch/livesample.gif (get)\nhttp://0.0.0.0:8080/myglitch/livesample.jpg (get)\nhttp://0.0.0.0:8080/myglitch/service (post)\nHapi server started @ http://0.0.0.0:8080\n```\n\nNow you can visit either of these URLs to see your glitch:\n```\nhttp://localhost:8080/myglitch/livesample.gif\nhttp://localhost:8080/myglitch/livesample.jpg\n```\n\nCool! Now, for faster iteration, using something like `nodemon` will help. It will basically restart the server whenever it detects a change. This means you can tweak your glitch and quickly see the results after saving:\n```\nnpm install -g nodemon\n```\nNow start the server with the `nodemon` command:\n```\nnodemon\n```\n\nLeave a browser window open pointing to `http://localhost:8080/myglitch/livesample.gif` and whenever you want to see the latest iteration just refresh the window.\n\nEven better: add your own image via the **moreSamples** option explained above to use a bigger and better image during development!\n\n\nModularize\n----------\n\nEventually you will want to just work with the glitch itself. Just pull it into its own file:\n\n**myglitch.js**\n```\nvar readimage = require('readimage'),\n    glitcher = require('glitcher'),\n    gifWriter = require('writegif');\n\nmodule.exports = function(buffer, callback) {\n\n    readimage(buffer, function(err, image) {\n        if (err) {\n            return callback(err);\n        }\n\n        if (image.frames.length == 1) {\n            glitcher.rainbowClamp(image.frames[0].data);\n        } else {\n            glitcher.rainbow(image.frames);\n        }\n\n        gifWriter(image, function(err, finalgif) {\n            return callback(null, finalgif);\n        });\n\n    });\n};\n```\n\nThen, just update the `options.glitches` in **index.js** to require in your new file.\n```\nserver.pack.register({\n    plugin: require('revisit-mutagen'),\n    options: {\n        glitches: {\n            'myglitch': require('./myglitch.js')\n        }\n    }\n}, function(err) {\n    if (err) throw err;\n    server.start(function() {\n\n        // list out all the routes for verification\n        server.table().forEach(function(row) {\n            console.log(server.info.uri + row.path + \" (\" + row.method + \")\");\n        });\n\n        console.log(\"Hapi server started @\", server.info.uri);\n    });\n\n});\n```\n\n**Extra Credit:** publish your glitch as a standalone module and publish it to npm!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflet%2Frevisit-mutagen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflet%2Frevisit-mutagen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflet%2Frevisit-mutagen/lists"}