🧩
Seanime Extensions
🧩
Seanime Extensions
  • Seanime
    • Getting started
    • Core APIs
    • Changelog
  • Content Providers
    • Write, test, share
    • Anime torrent provider
    • Manga provider
    • Online streaming provider
  • Plugins
    • Introduction
    • Write, test, share
    • APIs
      • Helpers
      • Store
      • Storage
      • Database
      • AniList
      • System
        • Permissions
        • OS
        • Filepath
        • Commands
        • Buffers, I/O
        • MIME
    • UI
      • Basics
      • User Interface
        • Tray
        • Toast
        • Screen
        • Command Palette
        • Action
        • DOM
      • Anime/Library
        • Anime
        • Playback
        • Continuity
        • Auto Downloader
        • Auto Scanner
        • Filler Manager
        • External Player Link
      • Downloading
        • Downloader
        • Torrent Client
      • Other
        • Manga
        • Discord
        • MPV
    • Hooks
    • Example
  • Frequently asked
    • Feature requests
Powered by GitBook
On this page
  • Permission
  • Usage
  • API
  • Example
  • Good to know
  1. Plugins
  2. APIs

Storage

Persistent storage.

Permission

storage permission is required.

my-plugin.json
{
    //...
    "plugin": {
        "permissions": {
            "scopes": ["storage"]
        }
    }
}

Usage

API

Unlike store , storage handles nested values out of the box.

$storage.set("foo.bar", 1)
$storage.set("foo.baz", "2")

$storage.has("foo") // true

$storage.get<number>("foo.bar") // 1
$storage.get<Record<string, any>>("foo") // { "bar": 1, "baz": "2" }

$storage.set("foo", "bar")
$storage.get("foo") // bar

$storage.watch("foo", (value) => {})

Example

my-plugin.ts
// A simple plugin that stores the history of scan durations
function init() {
    $app.onScanCompleted((e) => {
        // Store the scanning duration (in ms)
        $store.set("scan-completed", e.duration)
        
        e.next()
    })
    
    $ui.register((ctx) => {
    
        // Callback is triggered when the value is updated
        $store.watch<number>("scan-completed", (value) => {
            const date = new Date()
            const now = date.toISOString().replaceall(".", "_")
            
            // Add the value to the history
            $storage.set("scan-duration-history."+now, {
                duration: value,
                durationInSeconds: value/1000,
                addedAt: date,
            })
            
            ctx.toast.info(`Scanning took ${value/1000} seconds!`)
        })
        
        function deleteHistory() {
            $storage.remove("scan-duration-history")
        }
    })
}

Make sure your storage doesn't grow too big by doing some cleanup.

Good to know

The plugin storage is deleted when the plugin is uninstalled.

PreviousStoreNextDatabase

Last updated 1 month ago