npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ion-media-cache

v0.2.4

Published

Directive cache multimedia.

Downloads

75

Readme

Ion Media Cache

Directive cache multimedia.

Usage notice

With this directive you can download file to the device using Fetch API and render the source in the component. If your application is PWA, it use FileSystem to save the blob.

Supported Platforms.

* Android
* Browser
* Ios

Installation

npm i ion-media-cache@latest.

Require installation ionic native

File

ionic cordova plugin add cordova-plugin-file 
npm install @awesome-cordova-plugins/file 
ionic cap sync

Ionic Webview

ionic cordova plugin add cordova-plugin-ionic-webview 
npm install @awesome-cordova-plugins/ionic-webview 
ionic cap sync

fs-web

npm install fs-web --save

Quickstart

Import ion-media-cache in you module page.

// Import the module
import { IonMediaCacheModule } from 'ion-media-cache';
import { File } from '@ionic-native/file/ngx';
import { WebView } from '@ionic-native/ionic-webview/ngx';
...
@NgModule({
    (...)
    imports: [
        IonMediaCacheModule
    ],
    providers: [
        File,
        WebView
    ]
    (...)
})
export class PageModule {}

Usage

image

<img [url]="image" [customCache]="{fallbackUrl: '/assets/img/default.png'}" alt="ion-media-cache" />

<ion-img [url]="image" [customCache]="{fallbackUrl: '/assets/img/default.png'}"></ion-img>

custom div background

<div
    [url]="image"
    [customCache]="{fallbackUrl: '/assets/img/default.png', render: 'background-image', spinner: false, fallbackReload: false}"
    style="background-repeat: no-repeat;background-position: center;background-size: cover;width: 100%;height: 100%;">
</div>

audio

<audio controls name="media">
  <source [url]="audio" customCache>
</audio>

Events

<ion-img
    #elRef
    [url]="image"
    [customCache]="{ fallbackUrl: '/assets/img/bienvenida.png', cache_expire: {time: n.component?.expire_subimage, data: data } }"
    (onExpireCache)="onExpireCache($event, elRef)"
    (ionImgDidLoad)="ionImgDidLoad($event)"
    (ionError)="ionError($event)">
</ion-img>
onExpireCache(event) {
    console.log(event);
    event.el.clearImageCache(event.data.url);
}
ionImgDidLoad(event) {
    console.log(event);
}
ionError(event) {
    console.log(event);
}

Optional properties

customCache = {
    debugMode: false,                       // boolean default = false;
    enabled: true,                          // booleandefault = true;
    corsFromHeroku: '',                     // string = '' | 'http://cors-anywhere.herokuapp.com/'; fix https://stackoverflow.com/a/21136980/7638125
    fallbackUrl: '',                        // string usage uri fail 'assetes/img/default.png'.
    concurrency: 5,                         // number default = 5, only on android, ios.
    maxCacheSize: -1,                       // number default -1, without limit.
    maxCacheAge: -1,                        // number default -1, without limit.
    httpHeaders: {},                        // any default = {}.
    fileNameCachedWithExtension: true,      // boolean default = true, save file with extension.
    fallbackFileNameCachedExtension: '.jpg',// string default '.jpg', extension to save.
    cacheDirectoryType: 'external',         // 'cache' | 'data' | 'external' default = 'external'.
    imageReturnType: 'uri',                 // 'base64' | 'uri' default = 'uri'.
    cacheDirectoryName: 'ion-media-cache',  // string default = 'ion-media-cache'.
    cache_expire: undefined,                // any default undefined, usage { time: new Date().getTime() + (1000 * [unit_second]) }.
    cache: true,                           // boolean defaul = true, activeted cache.
    render: 'src',                          // string default, render to property src.
    spinner: `
    <ion-spinner name="crescent">
    </ion-spinner>`,                        // any usage innertHtml. or false to disabled spinner
    fallbackReload: `
    <ion-icon name="cloud-offline">
    </ion-icon>
    `,                                      // any;usage innertHtml. or false to disable fallbackReload

}
spinnerStyle // string [spinnerStyle]="'width: 100%;height: 100%'"
fallbackStyle // string [fallbackStyle]="'width: 100%;height: 100%'"

IonMediaCache

// Print current cache loader in the DOM
// Use console inspect in the browser
IonMediaCache
// print queue process
(window as any).currentlyProcessing

Maintain fs-web

import * as fs from 'fs-web';
declare const window;
window.fsWeb = fs;
// Remove all files
window.fsWeb.readdir('ion-media-cache').then((files) => {
    files.forEach((file) => {
        window.fsWeb.removeFile(file.path);
    });
});

To customize the response valid of the blob type

<div [typeBlob]="['text/html', 'application/octet-stream']"></div>

Testing fetch

fetch('http://cors-anywhere.herokuapp.com/https://lorempixel.com/640/480/?60789', {
   headers: {},
}).then((response) => {
   return response.blob();
}).then((blob) => {
   console.log(blob);
}).catch((e) => console.log(e));

Cors Erros Configuring Cors For Laravel Public Storage

fix stackoverflow

customCache = {
    corsFromHeroku: true // this is default false, limited use fix https://stackoverflow.com/a/21136980/7638125
}

CORS Anywhere is a NodeJS proxy which adds CORS headers to the proxied request.

If you expect lots of traffic, please host your own instance of CORS Anywhere, and make sure that the CORS Anywhere server only whitelists your site to prevent others from using your instance of CORS Anywhere as an open proxy.

Demo Server CORS Anywhere