Skip to content

Commit

Permalink
Merge branch 'dev' into mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
serefyarar committed May 21, 2024
2 parents 084380a + cc122dc commit c7bb260
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
18 changes: 17 additions & 1 deletion api/src/controllers/model.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createClient } from "redis";
import { indexNewModel } from "../libs/composedb.js";
import { indexNewModel, stopIndexingModels } from "../libs/composedb.js";

export const info = async (req, res) => {
const runtimeDefinition = req.app.get("runtimeDefinition");
Expand All @@ -26,3 +26,19 @@ export const deploy = async (req, res, next) => {
}
res.json(indexResult);
};

export const remove = async (req, res, next) => {
const pubClient = createClient({
url: process.env.REDIS_CONNECTION_STRING,
});
await pubClient.connect();
const indexResult = await stopIndexingModels(
req.app,
req.params.id,
req.headers.authorization,
);
if (indexResult) {
pubClient.publish("newModel", req.params.id);
}
res.json(indexResult);
};
27 changes: 27 additions & 0 deletions api/src/libs/composedb.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,33 @@ export const indexNewModel = async (app, modelId, ceramicAdminPrivateKey) => {

return true;
};

export const stopIndexingModels = async (
app,
modelId,
ceramicAdminPrivateKey,
) => {
const indexerCeramic = new CeramicClient(process.env.CERAMIC_HOST);
if (!ceramicAdminPrivateKey) {
return false;
}
const key = fromString(ceramicAdminPrivateKey, "base16");
const did = new DID({
resolver: getResolver(),
provider: new Ed25519Provider(key),
});
await did.authenticate();
if (!did.authenticated) {
return false;
}
indexerCeramic.did = did;

const models = await indexerCeramic.admin.stopIndexingModels([modelId]);

await setIndexedModelParams(app);

return models;
};
export const setIndexedModelParams = async (app) => {
await authenticateAdmin();
const models = await ceramic.admin.getIndexedModels();
Expand Down
10 changes: 10 additions & 0 deletions api/src/packages/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,16 @@ app.post(
modelController.deploy,
);

app.delete(
"/model/index/:id",
validator.params(
Joi.object({
id: Joi.custom(isStreamID, "Model ID").required(),
}),
),
modelController.remove,
);

// Validators
app.use(errorMiddleware);

Expand Down

0 comments on commit c7bb260

Please sign in to comment.