-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de73c02
commit 2f6ba45
Showing
4 changed files
with
75 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import type { Client, Models } from "@aw-labs/appwrite-console"; | ||
|
||
type Payload = { | ||
[key: string]: any; | ||
} | ||
|
||
class Service { | ||
static CHUNK_SIZE = 5*1024*1024; // 5MB | ||
|
||
client: Client; | ||
|
||
constructor(client: Client) { | ||
this.client = client; | ||
} | ||
|
||
static flatten(data: Payload, prefix = ''): Payload { | ||
let output: Payload = {}; | ||
|
||
for (const key in data) { | ||
let value = data[key]; | ||
let finalKey = prefix ? `${prefix}[${key}]` : key; | ||
|
||
if (Array.isArray(value)) { | ||
output = Object.assign(output, this.flatten(value, finalKey)); | ||
} | ||
else { | ||
output[finalKey] = value; | ||
} | ||
} | ||
|
||
return output; | ||
} | ||
} | ||
|
||
export class Project extends Service { | ||
constructor(client: Client) | ||
{ | ||
super(client); | ||
} | ||
|
||
/** | ||
* Get usage stats for a project | ||
* | ||
* | ||
* @param {string} range | ||
* @throws {AppwriteException} | ||
* @returns {Promise} | ||
*/ | ||
async getUsage(range?: string): Promise<Models.UsageProject> { | ||
let path = '/project/usage'; | ||
let payload: Payload = {}; | ||
|
||
console.log("Getting usage") | ||
console.log(range) | ||
|
||
if (typeof range !== 'undefined') { | ||
payload['range'] = range; | ||
} | ||
|
||
const uri = new URL(this.client.config.endpoint + path); | ||
return await this.client.call('get', uri, { | ||
'content-type': 'application/json', | ||
}, payload); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters