Skip to content

Commit

Permalink
fix getTypeIndexURL
Browse files Browse the repository at this point in the history
  • Loading branch information
soltanireza65 committed Dec 22, 2023
1 parent 870067a commit e164580
Showing 1 changed file with 7 additions and 25 deletions.
32 changes: 7 additions & 25 deletions src/TypeIndexHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,7 @@ export class TypeIndexHelper {
const profileMe = await this.getMeProfile(webId, fetch);

const typeIndexPredicate = TypeIndexHelper.getTypeIndexPredicate(isPrivate);
const typeIndexFileName = TypeIndexHelper.getTypeIndexFileName(isPrivate);
const typeIndexUrl = TypeIndexHelper.getTypeIndexURL(
webId,
typeIndexFileName
);
const typeIndexUrl = TypeIndexHelper.getDefaultTypeIndexURL(webId, isPrivate);

if (profileMe) {
let typeIndex = getNamedNode(profileMe, typeIndexPredicate);
Expand All @@ -107,8 +103,8 @@ export class TypeIndexHelper {

return namedNode(typeIndexUrl);
} else {
const typeIndexDS = await this.createTypeIndex(fetch, typeIndexUrl);
const profileDS = await getSolidDataset(webId, { fetch: fetch });
await this.createTypeIndex(fetch, typeIndexUrl);
const profileDS = await getSolidDataset(webId, { fetch });

const profileMeThing = buildThing(createThing({ name: "me" }))
.addNamedNode(typeIndexPredicate, namedNode(typeIndexUrl))
Expand Down Expand Up @@ -240,20 +236,6 @@ export class TypeIndexHelper {
} catch (error) { }
}

/**
* Returns the name of the typeIndexe file based on the isPrivate flag.
*
* @param isPrivate - Whether the typeIndexe file should be private or public.
* @returns The name of the typeIndexe file - either "privateTypeIndex" or "publicTypeIndex".
* @internal
*/
public static getTypeIndexFileName(
isPrivate: boolean
): "privateTypeIndex" | "publicTypeIndex" {
return isPrivate ? "privateTypeIndex" : "publicTypeIndex";
}


/**
* Returns the predicate to use for the typeIndexe based on whether it is private or public.
*
Expand All @@ -270,14 +252,14 @@ export class TypeIndexHelper {
* Generates the URL for the given user's typeIndexe file.
*
* @param webId - The user's WebID URL
* @param typeIndexFileName - The name of the typeIndexe file
* @param isPrivate - Whether the typeIndexe is private or public.
* @returns The full URL for the typeIndexe file in the user's /settings/ folder
* @internal
*/
public static getTypeIndexURL(
public static getDefaultTypeIndexURL(
webId: string,
typeIndexFileName: string
isPrivate: boolean,
): string {
return `${webId.split("/profile")[0]}/settings/${typeIndexFileName}.ttl`;
return `${webId.split("/profile")[0]}/settings/${isPrivate ? "privateTypeIndex" : "publicTypeIndex"}.ttl`;
}
}

0 comments on commit e164580

Please sign in to comment.