asmer@controller 5 years ago
parent
commit
ecd0677171
3 changed files with 23 additions and 10 deletions
  1. 16 1
      index.js
  2. 5 6
      models.js
  3. 2 3
      package-lock.json

+ 16 - 1
index.js

@@ -6,9 +6,13 @@ const express_graphql   = require('express-graphql');
 const { buildSchema, printSchema } = require('graphql');
 const expand = require('mm-graphql/expand')
 const fs     = require('fs')
+
 const uploadPath = `${__dirname}/public/images/`;
 const upload  = require('multer')({ dest: uploadPath })
 
+const uploadTrackPath = `${__dirname}/public/track/`;
+const uploadTrack  = require('multer')({ dest: uploadTrackPath, fieldSize: 1024*1024*128 })
+
 
 ;(async () => {
 
@@ -53,9 +57,19 @@ const upload  = require('multer')({ dest: uploadPath })
             url: String,
             originalFileName: String,
             owner: User
+            id3: ID3
             playlists: [Playlist]
         }
 
+        type ID3 {
+              title: String
+              artist: String
+              album: String
+              year: String
+              genre: String
+              trackNumber: String
+        }
+
         input TrackInput {
             _id: ID,
             playlists: [PlaylistInput]
@@ -70,6 +84,7 @@ const upload  = require('multer')({ dest: uploadPath })
             tracks: [Track]
         }
 
+
         input PlaylistInput {
             _id: ID,
             name: String
@@ -102,7 +117,7 @@ const upload  = require('multer')({ dest: uploadPath })
     })
 
 
-    app.post('/track', upload.single('track'), async (req, res, next) => {
+    app.post('/track', uploadTrack.single('track'), async (req, res, next) => {
         let decoded;
         console.log('wtf')
         if (decoded = jwtCheck(req, jwtSecret)){

+ 5 - 6
models.js

@@ -79,14 +79,13 @@ module.exports = async (dbName='player') => {
             static async fromFileData(fileData){
                 let track  = new Track({})
                 track.fileData = fileData
-                track.url      = `tracks/${fileData.filename}`
+                track.url      = `track/${fileData.filename}`
                 track.originalFileName = fileData.originalname
                 const NodeID3 = require('node-id3')
-                let data = await NodeID3.read(fileData.filename)
-                console.log('ID3', data)
+                track.id3 = await NodeID3.read(fileData.path)
 
-                await image.save()
-                return image;
+                await track.save()
+                return track;
             }
 
 
@@ -112,7 +111,7 @@ module.exports = async (dbName='player') => {
                 }
             }
         }
-        SlicedSavable.addClass(Collection)
+        SlicedSavable.addClass(Playlist)
 
 
 

+ 2 - 3
package-lock.json

@@ -480,13 +480,12 @@
         "express": "^4.17.1",
         "express-graphql": "^0.9.0",
         "graphql": "^14.4.2",
-        "jsonwebtoken": "^8.5.1",
-        "mm": "git+ssh://git@gitlab.a-level.com.ua:gitgod/mm.git#5d34f0c91cbf3acb9cdc59bdbeadee041758cea9"
+        "jsonwebtoken": "^8.5.1"
       },
       "dependencies": {
         "mm": {
           "version": "git+ssh://git@gitlab.a-level.com.ua:gitgod/mm.git#5d34f0c91cbf3acb9cdc59bdbeadee041758cea9",
-          "from": "git+ssh://git@gitlab.a-level.com.ua:gitgod/mm.git",
+          "from": "git+ssh://git@gitlab.a-level.com.ua:gitgod/mm.git#5d34f0c91cbf3acb9cdc59bdbeadee041758cea9",
           "requires": {
             "mongodb": "^3.2.2"
           }