1.1.5 • Published 2 years ago

@cloudfs/aliyun v1.1.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

CloudFS.

FS stand for File System.

A modern library for easy-managed and extendable multiple file systems.

Inspired by Laravel FileSystem

Supported Cloud Service Provider

Installation

yarn add @cloudfs/core
# or
npm install @cloudfs/core

Add NextJs Integration

yarn add @cloudfs/nestjs
# or
npm install @cloudfs/nestjs

Support Different Cloud Service Provider

yarn add @cloudfs/<cloud-service-provider-name>
# or
npm install @cloudfs/<cloud-service-provider-name>

Native JavaScript / TypeScript

import { AWSS3Adapter } from '@cloudfs/aws';
import { CloudFS } from 'filesystem';

const fileSystem = new CloudFS();

fileSystem.init({
  adapters: [
    { driver: 'local', adapter: LocalAdapter },
    { driver: 'aws-s3', adapter: AWSS3Adapter },
  ],
  drivers: {
    local: {
      driver: 'local',
      root: __dirname,
    },
    staticBucket: {
      driver: 'aws-s3',
      // ...
    },
  },
});

NestJS

// app.module.ts
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { FileSystemModule } from '@cloudfs/nestjs';
import { LocalAdapter } from '@cloudfs/core';
import { AWSS3Adapter } from '@cloudfs/aws';
import { AppService } from './app.service';

@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true }),
    FileSystemModule.forRootAsync({
      useFactory: (configService: ConfigService) => {
        console.log(configService.get('APP_ENV'));

        return {
          adapters: [
            { driver: 'local', adapter: LocalAdapter },
            { driver: 'aws-s3', adapter: AWSS3Adapter },
          ],
          drivers: {
            local: {
              driver: 'local',
              root: __dirname,
            },
            staticBucket: {
              driver: 'aws-s3',
              // ...
            },
          },
        };
      },
      inject: [ConfigService],
    }),
  ],
  controllers: [],
  providers: [AppService],
})
export class AppModule {}

Implementation

Native JavaScript / TypeScript Implementation

import { CloudFS } from 'filesystem';

const fileSystem = new CloudFS();

fileSystem.init({
  adapters: [{ driver: 'local', adapter: LocalAdapter }],
  drivers: {
    local: {
      driver: 'local',
      root: __dirname
    },
  },
});

// local is the key in drivers, not driver name.
const adapter = fileSystem.get('local');

// get file
const file = await adapter.get(filename: 'a.json');
const payload = JSON.parse(file);

NestJs Implementation

// app.module.ts
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { FileSystemModule } from '@cloudfs/nestjs';
import { LocalAdapter } from '@cloudfs/core';
import { AppService } from './app.service';

@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true }),
    FileSystemModule.forRootAsync({
      useFactory: (configService: ConfigService) => {
        console.log(configService.get('APP_ENV'));

        return {
          adapters: [{ driver: 'local', adapter: LocalAdapter }],
          drivers: {
            local: {
              driver: 'local',
              root: __dirname,
            },
          },
        };
      },
      inject: [ConfigService],
    }),
  ],
  controllers: [],
  providers: [AppService],
})
export class AppModule {}
// file.module.ts
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { FileSystemModule } from '@cloudfs/nestjs';
import { AppService } from './app.service';

@Module({
  imports: [FileSystemModule.forFeature(['local'])],
  controllers: [],
  providers: [AppService],
})
export class AppModule {}

Make sure your module have imports: [FileSystemModule.forFeature(['local'])]

// file.service.ts

import { Injectable } from '@nestjs/common';
import { FileSystem } from '@cloudfs/core';
import {
  FileSystemModule,
  InjectFileSystemAdapter,
  InjectFileSystem,
  FileSystem,
} from '@cloudfs/nestjs';

@Injectable()
export class FileService {
  constructor(
    @InjectFileSystem()
    private readonly fileSystem: FileSystem,
    @InjectFileSystemAdapter('local')
    private readonly localAdapter: LocalAdapter
  ) {}
}

Test Suite

We are decided temporary to skip some test, while the market have no the related emulator can be found. Only local, s3 adapter can be tested.


Feel free to create the PR to support more cloud service.

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago