Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/roc/Roc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ export class Roc<PublicUserInfo = unknown, PrivateUserInfo = unknown> {
data: RocEntryDocument<ContentType, IdType>,
options?: RocDocumentOptions,
) {
const url = new URL(`entry/${data._id}/`, this.dbUrl).href;
const url = new URL(`entry/${data._id}`, this.dbUrl).href;
return new RocDocument(data, createAxios(url, this.accessToken), options);
}

public getDocument<ContentType, IdType>(
uuid: string,
options?: RocDocumentOptions,
): RocDocument<ContentType, IdType> {
const url = new URL(`entry/${uuid}/`, this.dbUrl).href;
const url = new URL(`entry/${uuid}`, this.dbUrl).href;
return new RocDocument(uuid, createAxios(url, this.accessToken), options);
}

Expand Down
16 changes: 6 additions & 10 deletions src/roc/RocDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ export class RocDocument<
responseType: 'text' | 'arraybuffer' | 'blob',
axiosOptions?: RocAxiosRequestOptions,
): Promise<Buffer | string> {
const url = new URL(name, this.getBaseUrl()).href;
const response = await this.request({
url,
const response = await this.request.get(name, {
responseType,
...axiosOptions,
});
Expand All @@ -68,7 +66,7 @@ export class RocDocument<
if (rev) {
throw new Error('UNIMPLEMENTED fetch with rev');
}
const response = await this.request.get('/', axiosOptions);
const response = await this.request.get('', axiosOptions);
this.value = response.data;
return response.data;
}
Expand Down Expand Up @@ -111,7 +109,7 @@ export class RocDocument<
}

// Send the new doc
await this.request.put('/', newDoc, axiosOptions);
await this.request.put('', newDoc, axiosOptions);

// Get the new document
// With updated properties ($lastModifification...)
Expand Down Expand Up @@ -139,14 +137,15 @@ export class RocDocument<
}

public async delete(axiosOptions?: RocAxiosRequestOptions) {
const response = await this.request.delete('/', axiosOptions);
const response = await this.request.delete('', axiosOptions);
if (response.data.ok) {
this.value = undefined;
this.deleted = true;
} else {
throw new Error('document was not deleted');
}
}

public getAttachment(name: string): RocAttachment {
if (this.value === undefined) {
throw new RocClientError(
Expand All @@ -161,7 +160,7 @@ export class RocDocument<
return {
...attachments[name],
name,
url: `${this.getBaseUrl()}${name}`,
url: this.request.getUri({ url: name }),
};
}

Expand All @@ -182,9 +181,6 @@ export class RocDocument<
return response.data;
}

protected getBaseUrl() {
return this.request.defaults.baseURL || '';
}
private async _fetchIfUnfetched() {
if (this.value === undefined) {
await this.fetch();
Expand Down