MCPcopy Create free account
hub / github.com/decaporg/decap-cms / storeMetadata

Method storeMetadata

packages/decap-cms-backend-github/src/API.ts:457–485  ·  view source on GitHub ↗
(key: string, data: Metadata)

Source from the content-addressed store, hash-verified

455 }
456
457 async storeMetadata(key: string, data: Metadata) {
458 // semaphore ensures metadata updates are always ordered, even if
459 // calls to storeMetadata are not. concurrent metadata updates
460 // will result in the metadata branch being unable to update.
461 if (!this._metadataSemaphore) {
462 this._metadataSemaphore = semaphore(1);
463 }
464 return new Promise<void>((resolve, reject) =>
465 this._metadataSemaphore?.take(async () => {
466 try {
467 const branchData = await this.checkMetadataRef();
468 const file = { path: `${key}.json`, raw: JSON.stringify(data) };
469
470 await this.uploadBlob(file);
471 const changeTree = await this.updateTree(branchData.sha, [file as TreeFile]);
472 const { sha } = await this.commit(`Updating “${key}” metadata`, changeTree);
473 await this.patchRef('meta', '_decap_cms', sha);
474 await localForage.setItem(`gh.meta.${key}`, {
475 expires: Date.now() + 300000, // In 5 minutes
476 data,
477 });
478 this._metadataSemaphore?.leave();
479 resolve();
480 } catch (err) {
481 reject(err);
482 }
483 }),
484 );
485 }
486
487 deleteMetadata(key: string) {
488 if (!this._metadataSemaphore) {

Callers 1

migrateToVersion1Method · 0.95

Calls 5

checkMetadataRefMethod · 0.95
uploadBlobMethod · 0.95
updateTreeMethod · 0.95
commitMethod · 0.95
patchRefMethod · 0.95

Tested by

no test coverage detected