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

fake.js 999B

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