stashapp-api
Version:
Easy to use adapter for interaction with a Stash server through GraphQL.
145 lines (144 loc) • 5.16 kB
JavaScript
import { CriterionModifier as _CriterionModifier, GenderEnum as _GenderEnum, } from "./generated/graphql.js";
export const CriterionModifier = _CriterionModifier;
export const GenderEnum = _GenderEnum;
import { GraphQLClient } from "graphql-request";
import { getSdk } from "./generated/graphql.js";
/**
* Singleton class for interacting with the Stash GraphQL API.
* Provides type-safe query and mutation methods.
*/
export class StashApp {
static instance;
client;
sdk;
/** Find performers */
findPerformers;
/** Find studios */
findStudios;
/** Find scenes */
findScenes;
/** Find scenes (compact - trimmed nested objects for better performance) */
findScenesCompact;
/** Find tags */
findTags;
/** Find groups */
findGroups;
/** Find a single group */
findGroup;
/** Find galleries */
findGalleries;
/** Find a single gallery */
findGallery;
/** Find images */
findImages;
/** Find scene IDs only (lightweight for bulk operations) */
findSceneIDs;
/** Find performer IDs only (lightweight for bulk operations) */
findPerformerIDs;
/** Find studio IDs only (lightweight for bulk operations) */
findStudioIDs;
/** Find tag IDs only (lightweight for bulk operations) */
findTagIDs;
/** Find group IDs only (lightweight for bulk operations) */
findGroupIDs;
/** Find gallery IDs only (lightweight for bulk operations) */
findGalleryIDs;
/** Find image IDs only (lightweight for bulk operations) */
findImageIDs;
/** Update a scene */
sceneUpdate;
/** Update multiple scenes */
scenesUpdate;
/** Update a performer */
performerUpdate;
/** Update a studio */
studioUpdate;
/** Update a gallery */
galleryUpdate;
/** Update a group */
groupUpdate;
/** Update an image */
imageUpdate;
/** Start a metadata scan - returns job ID */
metadataScan;
/** Destroy a performer */
performerDestroy;
/** Destroy multiple performers */
performersDestroy;
/** Destroy a tag */
tagDestroy;
/** Destroy multiple tags */
tagsDestroy;
/** Destroy a studio */
studioDestroy;
/** Destroy multiple studios */
studiosDestroy;
/** Destroy a scene */
sceneDestroy;
/** Create a tag */
tagCreate;
/** Update a tag */
tagUpdate;
/** Increment scene O counter */
sceneIncrementO;
/** Decrement scene O counter */
sceneDecrementO;
/** Save scene activity (resume time and play duration) */
sceneSaveActivity;
/** Add play history timestamp(s) to scene */
sceneAddPlay;
/** Get Stash configuration including library paths */
configuration;
constructor(config) {
this.client = new GraphQLClient(config.url, {
headers: { ApiKey: config.apiKey },
});
this.sdk = getSdk(this.client);
this.findPerformers = this.sdk.FindPerformers;
this.findStudios = this.sdk.FindStudios;
this.findScenes = this.sdk.FindScenes;
this.findScenesCompact = this.sdk.FindScenesCompact;
this.findTags = this.sdk.FindTags;
this.findGroups = this.sdk.FindGroups;
this.findGroup = this.sdk.FindGroup;
this.findGalleries = this.sdk.FindGalleries;
this.findGallery = this.sdk.FindGallery;
this.findImages = this.sdk.FindImages;
this.findSceneIDs = this.sdk.FindSceneIDs;
this.findPerformerIDs = this.sdk.FindPerformerIDs;
this.findStudioIDs = this.sdk.FindStudioIDs;
this.findTagIDs = this.sdk.FindTagIDs;
this.findGroupIDs = this.sdk.FindGroupIDs;
this.findGalleryIDs = this.sdk.FindGalleryIDs;
this.findImageIDs = this.sdk.FindImageIDs;
this.sceneUpdate = this.sdk.sceneUpdate;
this.scenesUpdate = this.sdk.scenesUpdate;
this.performerUpdate = this.sdk.performerUpdate;
this.studioUpdate = this.sdk.studioUpdate;
this.galleryUpdate = this.sdk.galleryUpdate;
this.groupUpdate = this.sdk.groupUpdate;
this.imageUpdate = this.sdk.imageUpdate;
this.metadataScan = this.sdk.metadataScan;
this.performerDestroy = this.sdk.performerDestroy;
this.performersDestroy = this.sdk.performersDestroy;
this.tagDestroy = this.sdk.tagDestroy;
this.tagsDestroy = this.sdk.tagsDestroy;
this.studioDestroy = this.sdk.studioDestroy;
this.studiosDestroy = this.sdk.studiosDestroy;
this.sceneDestroy = this.sdk.sceneDestroy;
this.tagCreate = this.sdk.tagCreate;
this.tagUpdate = this.sdk.tagUpdate;
this.sceneIncrementO = this.sdk.sceneIncrementO;
this.sceneDecrementO = this.sdk.SceneDecrementO;
this.sceneSaveActivity = this.sdk.SceneSaveActivity;
this.sceneAddPlay = this.sdk.SceneAddPlay;
this.configuration = this.sdk.Configuration;
}
/** Initialize the singleton StashApp instance */
static init(config) {
if (!StashApp.instance) {
StashApp.instance = new StashApp(config);
}
return StashApp.instance;
}
}