mirror of
https://github.com/skidoodle/hostinfo
synced 2026-04-28 01:27:36 +02:00
half way there
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import type { HostInfo } from './types';
|
||||
|
||||
export const StorageService = {
|
||||
/**
|
||||
* Returns the storage key for a specific tab with the required type prefix
|
||||
*/
|
||||
getKey(tabId: number): `session:${string}` {
|
||||
return `session:host-info-${tabId}`;
|
||||
},
|
||||
|
||||
/**
|
||||
* Save host info for a tab
|
||||
*/
|
||||
async set(tabId: number, data: HostInfo) {
|
||||
await storage.setItem<HostInfo>(this.getKey(tabId), data);
|
||||
},
|
||||
|
||||
/**
|
||||
* Get host info for a tab
|
||||
*/
|
||||
async get(tabId: number): Promise<HostInfo | null> {
|
||||
return await storage.getItem<HostInfo>(this.getKey(tabId));
|
||||
},
|
||||
|
||||
/**
|
||||
* Clear data when a tab is closed
|
||||
*/
|
||||
async remove(tabId: number) {
|
||||
await storage.removeItem(this.getKey(tabId));
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user