ng-fad-one-drive
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

Getting started

Installation

npm install ng-fad-one-drive

It is important to configure your application in: Click here

Dependencies

npm install @fadportal/portal-models

Description

a) Gets the list of files on one drive. The search is done by filtering through a query where the results can coincide in several fields such as file name, metadata and file content Click here

b) Gets the base64 and blob of the selected file

Import

In the necessary file example.component.ts import the service.

import { FadOneDriveService } from 'ng-fad-one-drive';
.
.
.
...  constructor(private oneDrive: FadOneDriveService) { }

Usage

Typescript

Listen to the events and execute methods:

Inject service called FadOneDriveService Before using any method it is important to initialize that one drive requires with the method initOneDrive To see the errors it is necessary to subscribe to the method onErrorOneDrive

  private request = { scopes: ['openid', 'profile', 'User.Read', 'Files.Read.All'] };
  private configuration = {
      auth: {
        clientId: 'YOUR_CLIENT_ID',
        authority: 'https://login.microsoftonline.com/consumers',
        redirectUri: `YOUR REDIRECT ROUTE example: https://localhost:4200/one-drive`,
      },
      cache: {
        cacheLocation: 'sessionStorage',
        storeAuthStateInCookie: false,
      }
    }

  constructor(private oneDrive: FadOneDriveService) { }

  ngOnInit(): void {
    // Observe errors
    this.onerror();

    // Observe files
    this.ongetfiles();
  }

  getFiles() {
    /**
     * Initializaton of One Drive
     * @param {string} request Necessary data to obtain files
     * @param {string} configuration Necessary data to login
     * @return {Promise<boolean>} Always is true
     */
    await this.oneDrive.initOneDrive(this.request, this.configuration);

    /**
     * Trigger get files
     * @param {string} q Filter to One Drive list
     * @param {number} size Number of files per response
     */
    const q = 'nombre_del_archivo';
    const size = null;
    this.oneDrive.getOneDriveFiles(q, size);
  }

  async getFile(file: FadOneDriveModelFileList) {
    /**
     * Get base64 of One Drive file
     * @param {string} url Your url file. That is provided by each item of the files and the propertie is called @microsoft.graph.downloadUrl
     * @return {Promise<FadOneDriveModelFileFormat>}
     */
    const url = file['@microsoft.graph.downloadUrl'];
    const data = await this.oneDrive.getOneDriveFile(url);
    console.log(data);
  }

  ongetfiles() {
    /**
     * Get items from one drive account 
     * @return {Observable<FadOneDriveModelFileList[]>}
     */

    this.oneDrice.onGetOneDriveFiles().subscribe(res => {
      // One Drive files
      console.log(res);
    });
  }

  onerror() {
    /**
     * Get errors from service
     * @return {Observable<FadPortalModelErrorModule>}
     */

    this.oneDrive.onErrorOneDrive().subscribe(res => {
      // Manage errors
      console.log(res);
    });
  }

Readme

Keywords

none

Package Sidebar

Install

npm i ng-fad-one-drive

Weekly Downloads

1

Version

1.2.0

License

none

Unpacked Size

282 kB

Total Files

89

Last publish

Collaborators

  • fad-producto-test
  • psoto-naat
  • fad-producto