Storage

Key-value persistent storage for Spotube plugins.

Declare "PERSISTENT_STORAGE" in plugin.json capabilities. Data is stored per-plugin and persists across sessions.

Consuming

Obtain the service in main() via zipline.take(), then pass it to any implementation that needs persistent storage:

import dev.krtirtho.plugin_interfaces.host_apis.PersistedStorageAPI
import dev.krtirtho.plugin_interfaces.host_apis.PersistedStorageAPI_SERVICE_NAME

fun main() {
    val storage = zipline.take<PersistedStorageAPI>(PersistedStorageAPI_SERVICE_NAME)

    zipline.bind<CoreAPI>(CoreAPI_SERVICE_NAME, RealCoreAPI(storage))
}

Receive it in your service class via the constructor.

Interface

interface PersistedStorageAPI : ZiplineService {
    suspend fun putString(key: String, value: String)
    suspend fun getString(key: String): String?
    suspend fun remove(key: String)
    suspend fun getKeys(): List<String>
}

Usage

Store authentication tokens, preferences, cached data, and any other string values your plugin needs to persist.

// Store values
storage.putString("access_token", "abc123")
storage.putString("refresh_token", "xyz789")

// Retrieve
val token = storage.getString("access_token")

// List all stored keys
val keys = storage.getKeys()

// Remove
storage.remove("access_token")

Values are always strings. For structured data, serialize to JSON with kotlinx.serialization before storing.