xiongzhu 2 éve
szülő
commit
c9e3f43155
2 módosított fájl, 36 hozzáadás és 6 törlés
  1. 34 5
      database/seeders/File.ts
  2. 2 1
      database/seeders/Series.ts

+ 34 - 5
database/seeders/File.ts

@@ -27,10 +27,39 @@ export default class extends BaseSeeder {
             // 填写Bucket名称。
             bucket: Env.get('OSS_BUCKET')
         })
-        const dirs = await client.listV2({
-            prefix: 'files/',
-            delimiter: '/'
-        })
-        console.log(dirs)
+        // const dirs = await client.listV2({
+        //     prefix: 'files/asdf',
+        //     delimiter: '/'
+        // })
+        // console.log(dirs)
+        const downloaded = '/Volumes/Data HD/shortplay/downloaded'
+        const dir = '/Volumes/Data HD/shortplay/files'
+        const subDirs = fs
+            .readdirSync(downloaded)
+            .filter((file) => {
+                const stat = fs.statSync(path.join(downloaded, file))
+                return !stat.isDirectory() && !/^\./.test(file)
+            })
+            .sort()
+            .map((file) => {
+                return file.replace('.json', '')
+            })
+        for (let i = 0; i < 10; i++) {
+            const subDir = subDirs[i]
+            const files = fs.readdirSync(path.join(dir, subDir)).filter((file) => {
+                const stat = fs.statSync(path.join(dir, subDir, file))
+                return !stat.isDirectory()
+            })
+            const cover = files.find((file) => /^cover_/.test(file))
+
+            if (cover) {
+                const key = path.join('files', subDir, cover)
+                try {
+                    await client.head(key)
+                    await client.putACL(key, 'public-read')
+                    console.log('exists', key)
+                } catch (error) {}
+            }
+        }
     }
 }

+ 2 - 1
database/seeders/Series.ts

@@ -17,7 +17,8 @@ export default class extends BaseSeeder {
             const series = await Series.create({
                 title: data.video.title,
                 cover: data.video.img,
-                price: new Decimal('999')
+                price: new Decimal('999'),
+                totalEpisodes: data.video.total
             })
 
             let i = 0