Turn audio into a shareable video. forked from nypublicradio/audiogram

fake.js 848B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. var fs = require("fs"),
  2. path = require("path"),
  3. rimraf = require("rimraf"),
  4. mkdirp = require("mkdirp");
  5. module.exports = function(storagePath) {
  6. function copy(source, destination, cb) {
  7. if (!path.isAbsolute(source)) {
  8. source = path.join(storagePath, source);
  9. }
  10. if (!path.isAbsolute(destination)) {
  11. destination = path.join(storagePath, destination);
  12. }
  13. mkdirp.sync(path.dirname(destination));
  14. var readable = fs.createReadStream(source).on("error", cb),
  15. writeable = fs.createWriteStream(destination).on("error", cb).on("close", cb);
  16. readable.pipe(writeable);
  17. }
  18. function clean(cb) {
  19. rimraf(storagePath, cb);
  20. }
  21. function getURL(id) {
  22. return "/video/" + id + ".mp4";
  23. }
  24. return {
  25. upload: copy,
  26. download: copy,
  27. getURL: getURL,
  28. clean: clean
  29. };
  30. };