moxb:file-mirror-service

v0.0.1Published 2 years ago

File mirror service

This package provides a simple-to-use file mirror service, on top ot ostrio:files.

Quick start guide

In your server boot-up code, do something like this:

1import { createMirrorService } from 'meteor/moxb:file-mirror-service';
2
3Meteor.startup(() => {
4    const fileStoragePath = process.env[PATH_VAR_NAME];
5
6    if (!fileStoragePath) {
7        throw new Error(`"Please configure the ${PATH_VAR_NAME} env variable!`);
8    }
9    createMirrorService({
10        fileStoragePath,
11    });
12}); 

After this, you can access the service via getMirrorService().

To mirror a file:

1getMirrorService().mirrorFileAsync({ url: 'http://whatever.com/image.jpg'});

This will return a promise.

To get info about a mirrored file:

1getMirrorService().getFileInfo({ originalUrl: 'http://magic.com/mushroom.jpg'});

This will (synchronously) return a bunch of information stored about the requested file (assuming that we have it), including file type, local path, and the URL which can be used to access it.