upload.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. const Base = require('./base.js');
  2. const fs = require('fs');
  3. module.exports = class extends Base {
  4. async brandPicAction() {
  5. const brandFile = this.file('brand_pic');
  6. if (think.isEmpty(brandFile)) {
  7. return this.fail('保存失败');
  8. }
  9. const that = this;
  10. const filename = '/static/upload/brand/' + think.uuid(32) + '.jpg';
  11. const is = fs.createReadStream(brandFile.path);
  12. const os = fs.createWriteStream(think.ROOT_PATH + '/www' + filename);
  13. is.pipe(os);
  14. return that.success({
  15. name: 'brand_pic',
  16. fileUrl: 'http://127.0.0.1:8360' + filename
  17. });
  18. }
  19. async brandNewPicAction() {
  20. const brandFile = this.file('brand_new_pic');
  21. if (think.isEmpty(brandFile)) {
  22. return this.fail('保存失败');
  23. }
  24. const that = this;
  25. const filename = '/static/upload/brand/' + think.uuid(32) + '.jpg';
  26. const is = fs.createReadStream(brandFile.path);
  27. const os = fs.createWriteStream(think.ROOT_PATH + '/www' + filename);
  28. is.pipe(os);
  29. return that.success({
  30. name: 'brand_new_pic',
  31. fileUrl: 'http://127.0.0.1:8360' + filename
  32. });
  33. }
  34. async categoryWapBannerPicAction() {
  35. const imageFile = this.file('wap_banner_pic');
  36. if (think.isEmpty(imageFile)) {
  37. return this.fail('保存失败');
  38. }
  39. const that = this;
  40. const filename = '/static/upload/category/' + think.uuid(32) + '.jpg';
  41. const is = fs.createReadStream(imageFile.path);
  42. const os = fs.createWriteStream(think.ROOT_PATH + '/www' + filename);
  43. is.pipe(os);
  44. return that.success({
  45. name: 'wap_banner_url',
  46. fileUrl: 'http://127.0.0.1:8360' + filename
  47. });
  48. }
  49. async topicThumbAction() {
  50. const imageFile = this.file('scene_pic_url');
  51. if (think.isEmpty(imageFile)) {
  52. return this.fail('保存失败');
  53. }
  54. const that = this;
  55. const filename = '/static/upload/topic/' + think.uuid(32) + '.jpg';
  56. const is = fs.createReadStream(imageFile.path);
  57. const os = fs.createWriteStream(think.ROOT_PATH + '/www' + filename);
  58. is.pipe(os);
  59. return that.success({
  60. name: 'scene_pic_url',
  61. fileUrl: 'http://127.0.0.1:8360' + filename
  62. });
  63. }
  64. };