From 63e5980d3edf8cdcbca0a21cb434dfa50393f4a7 Mon Sep 17 00:00:00 2001 From: cyl19970726 <15258378443@163.com> Date: Wed, 1 Mar 2023 15:14:23 +0800 Subject: [PATCH] update hasPersmission --- src/storage/ETHStorage.ts | 11 +++-------- src/storage/SLIStorage.ts | 10 +++------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/storage/ETHStorage.ts b/src/storage/ETHStorage.ts index 8c5d5a9..06e758b 100644 --- a/src/storage/ETHStorage.ts +++ b/src/storage/ETHStorage.ts @@ -19,15 +19,10 @@ export class ETHStorage implements Storage { return Promise.resolve(Status.SUCCEED) } - async repoRoles(): Promise { - let owner = await this.contract.repoOwner(Buffer.from(this.repoName)) - if (owner === ethers.constants.AddressZero) return [] - return [owner] - } - async hasPermission(ref: string): Promise { - let member = await this.repoRoles() - return member.indexOf(await this.wallet.getAddress()) >= 0 + let sender = await this.wallet.getAddress() + let isMember = await this.contract.isRepoMembership(Buffer.from(this.repoName),sender) + return isMember } async download(path: string): Promise<[Status, Buffer]> { diff --git a/src/storage/SLIStorage.ts b/src/storage/SLIStorage.ts index 83701c6..a30eaf8 100644 --- a/src/storage/SLIStorage.ts +++ b/src/storage/SLIStorage.ts @@ -51,15 +51,11 @@ export class SLIStorage implements Storage { }) } - async repoRoles(): Promise { - let owner = await this.contract.repoOwner(Buffer.from(this.repoName)) - if (owner === ethers.constants.AddressZero) return [] - return [owner] - } async hasPermission(ref: string): Promise { - let member = await this.repoRoles() - return member.indexOf(await this.wallet.getAddress()) >= 0 + let sender = await this.wallet.getAddress() + let isMember = await this.contract.isRepoMembership(Buffer.from(this.repoName),sender) + return isMember } async download(path: string): Promise<[Status, Buffer]> {