|
|
@@ -1,20 +1,36 @@
|
|
|
+import Env from '@ioc:Adonis/Core/Env'
|
|
|
import BaseSeeder from '@ioc:Adonis/Lucid/Seeder'
|
|
|
import Drive from '@ioc:Adonis/Core/Drive'
|
|
|
import * as fs from 'fs'
|
|
|
import * as path from 'path'
|
|
|
+import OSS from 'ali-oss'
|
|
|
export default class extends BaseSeeder {
|
|
|
public async run() {
|
|
|
// Write your database queries inside the run method
|
|
|
- const dir = '/Volumes/Data HD/shortplay/files/08F2CNhR'
|
|
|
- await Promise.all(
|
|
|
- fs
|
|
|
- .readdirSync(dir)
|
|
|
- .map((file) =>
|
|
|
- Drive.putStream(
|
|
|
- path.join('files/08F2CNhR', file),
|
|
|
- fs.createReadStream(path.join(dir, file))
|
|
|
- )
|
|
|
- )
|
|
|
- )
|
|
|
+ // const dir = '/Volumes/Data HD/shortplay/files/08F2CNhR'
|
|
|
+ // await Promise.all(
|
|
|
+ // fs
|
|
|
+ // .readdirSync(dir)
|
|
|
+ // .map((file) =>
|
|
|
+ // Drive.putStream(
|
|
|
+ // path.join('files/08F2CNhR', file),
|
|
|
+ // fs.createReadStream(path.join(dir, file))
|
|
|
+ // )
|
|
|
+ // )
|
|
|
+ // )
|
|
|
+ const client = new OSS({
|
|
|
+ // yourregion填写Bucket所在地域。以华东1(杭州)为例,Region填写为oss-cn-hangzhou。
|
|
|
+ region: Env.get('OSS_REGION'),
|
|
|
+ // 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
|
|
|
+ accessKeyId: Env.get('OSS_KEY'),
|
|
|
+ accessKeySecret: Env.get('OSS_SECRET'),
|
|
|
+ // 填写Bucket名称。
|
|
|
+ bucket: Env.get('OSS_BUCKET')
|
|
|
+ })
|
|
|
+ const dirs = await client.listV2({
|
|
|
+ prefix: 'files/',
|
|
|
+ delimiter: '/'
|
|
|
+ })
|
|
|
+ console.log(dirs)
|
|
|
}
|
|
|
}
|