All files / app/mods/system cache.ts

100% Statements 4/4
100% Branches 0/0
100% Functions 0/0
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127117x       117x                                                                                                                                                                                                   117x                                   117x            
import { DateTime } from 'luxon';
import { Plugin } from '../../model/plugin';
import { Mod } from '../../model/tag';
 
export const cachePlugin: Plugin = {
  tag: '_plugin/cache',
  name: $localize`🗜️ Cache`,
  config: {
    mod: $localize`🗜️ Cache`,
    version: 2,
    default: true,
    generated: $localize`Generated by jasper-ui ${DateTime.now().toISO()}`,
    settings: $localize`cache`,
    submit: $localize`🗜️ cache`,
    internal: true,
    icons: [
      { label: $localize`🗜️`, thumbnail: $localize`🗜️`, order: -10 },
      { label: $localize`⭕️`, condition: 'thumbnail', title: $localize`Thumbnail`, order: -1 },
      { label: $localize`🙅️`, condition: 'ban', title: $localize`Banned`, order: 10 },
      { label: $localize`⛔️`, condition: '!id', title: $localize`Broken`, order: 10 },
    ],
    filters: [
      { query: '_plugin/cache', label: $localize`🗜️ cache`, title: $localize`Has cache entry`, group: $localize`Plugins 🧰️` },
      { scheme: 'cache:', label: $localize`cache:`, group: $localize`Schemes 🏳️️`},
    ],
    sorts: [
      { sort: 'plugins->_plugin/cache->contentLength:num', label: $localize`🗜️ size`, title: $localize`Cache size` },
    ],
    sortHelp: $localize`Sort by cache size.`,
    description: $localize`Cache remote resources locally.
    If you delete a Ref it's cached file will not be removed from storage right away.
    If you restore a Ref before the cache is cleared you also recover the cached file.
    Clicking "empty recycle bin" will immediately free up storage space.`,
    hasClearCache: $localize`🗑️ purge deleted from storage`,
    clearCacheConfirm: $localize`Warning!
This is very slow and expensive if you have a large cache.
 
Files which have only had their Ref deleted can still be recovered, but after this they will be permanently deleted.
 
Are you sure you want to purge deleted files from storage?`,
    // language=HTML
    snippet: `
      <script>
        Handlebars.registerHelper('readableBytes', (size) => {
          const i = !size ? 0 : Math.floor(Math.log(size) / Math.log(1024));
          return (size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
        });
      </script>
    `,
    // language=Handlebars
    infoUi: `{{#if contentLength}}<span title="{{mimeType}}">{{readableBytes contentLength}}</span>{{/if}}`,
    advancedForm: [{
      key: 'id',
      type: 'string',
      props: {
        label: $localize`Cache ID:`,
      }
    }, {
      key: 'mimeType',
      type: 'string',
      props: {
        label: $localize`Mime Type:`,
      }
    }, {
      key: 'contentLength',
      type: 'number',
      props: {
        label: $localize`Content Length:`,
      }
    }, {
      key: 'ban',
      type: 'boolean',
      props: {
        label: $localize`Banned:`,
      }
    }, {
      key: 'noStore',
      type: 'boolean',
      props: {
        label: $localize`Proxy Only:`,
        title: $localize`Do not store file, but allow fetching as a proxy.`,
      }
    }, {
      key: 'thumbnail',
      type: 'boolean',
      props: {
        label: $localize`Thumbnail:`,
      }
    }],
  },
  schema: {
    optionalProperties: {
      id: { type: 'string' },
      mimeType: { type: 'string' },
      contentLength: { type: 'uint32' },
      ban: { type: 'boolean' },
      noStore: { type: 'boolean' },
      thumbnail: { type: 'boolean' },
    }
  }
};
 
export const asyncCachePlugin: Plugin = {
  tag: '_plugin/delta/cache',
  name: $localize`🗜️ Async Cache`,
  config: {
    mod: $localize`🗜️ Cache`,
    version: 1,
    default: true,
    generated: $localize`Generated by jasper-ui ${DateTime.now().toISO()}`,
    actions: [
      { tag: '_plugin/delta/cache', labelOn: $localize`cancel`, title: $localize`Cancel saving this Ref resource to the cache.` },
    ],
    advancedActions: [
      { tag: '_plugin/delta/cache', scheme: 'http:', labelOff: $localize`cache`, title: $localize`Save the Ref resource in the cache`, confirm: $localize`Are you sure you want to cache?`, global: true },
      { tag: '_plugin/delta/cache', scheme: 'https:', labelOff: $localize`cache`, title: $localize`Save the Ref resource in the cache`, confirm: $localize`Are you sure you want to cache?`, global: true },
    ],
  },
};
 
export const cacheMod: Mod = {
  plugin: [
    cachePlugin,
    asyncCachePlugin,
  ],
};