feat(pihole): add support for v6 (#2448)
* feat(pihole): add support for v6 * fix: add session-store to keep using same session for pi-hole requests * chore: address pull request feedback * fix: import issue * fix: other import errors
This commit is contained in:
29
packages/integrations/src/base/session-store.ts
Normal file
29
packages/integrations/src/base/session-store.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { decryptSecret, encryptSecret } from "@homarr/common/server";
|
||||
import { logger } from "@homarr/log";
|
||||
import { createGetSetChannel } from "@homarr/redis";
|
||||
|
||||
const localLogger = logger.child({ module: "SessionStore" });
|
||||
|
||||
export const createSessionStore = (integration: { id: string }) => {
|
||||
const channelName = `session-store:${integration.id}`;
|
||||
const channel = createGetSetChannel<`${string}.${string}`>(channelName);
|
||||
|
||||
return {
|
||||
async getAsync() {
|
||||
localLogger.debug("Getting session from store", { store: channelName });
|
||||
const value = await channel.getAsync();
|
||||
if (!value) return null;
|
||||
return decryptSecret(value);
|
||||
},
|
||||
async setAsync(value: string) {
|
||||
localLogger.debug("Updating session in store", { store: channelName });
|
||||
await channel.setAsync(encryptSecret(value));
|
||||
},
|
||||
async clearAsync() {
|
||||
localLogger.debug("Cleared session in store", { store: channelName });
|
||||
await channel.removeAsync();
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export type SessionStore = ReturnType<typeof createSessionStore>;
|
||||
Reference in New Issue
Block a user