Skip to content

Commit

Permalink
#9 - Review
Browse files Browse the repository at this point in the history
  • Loading branch information
kristianbinau committed Oct 5, 2023
1 parent 4e3fba0 commit 0a2623d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
21 changes: 6 additions & 15 deletions src/components/files/FileBrowser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,13 @@ const items = ref<ItemClass[]>([]);
getItems();
function getItems() {
fetch(
api(
`item${
ItemClass.isItem(props.modelValue) && FolderClass.isFolder(props.modelValue)
? `/${props.modelValue.id}`
: ''
}`,
),
{
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
credentials: 'include',
fetch(api(`item${FolderClass.isFolder(props.modelValue) ? `/${props.modelValue.id}` : ''}`), {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
)
credentials: 'include',
})
.then(async (response) => {
if (!response.ok) {
if (response.status >= 400 && response.status < 500) {
Expand Down
4 changes: 3 additions & 1 deletion src/lib/items/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export class FileClass extends ItemClass {
return this._blobUrl;
}

static isFile(object: ItemType): object is FileType {
static isFile(object: any): object is FileType {
if (!ItemClass.isItem(object)) return false;

// BlobUrl
if (!('blobUrl' in object && typeof object.blobUrl === 'string')) return false;

Expand Down
4 changes: 3 additions & 1 deletion src/lib/items/folders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export class FolderClass extends ItemClass {
] as FolderColor;
}

static isFolder(object: ItemType): object is FolderType {
static isFolder(object: any): object is FolderType {
if (!ItemClass.isItem(object)) return false;

// Color
if (!('color' in object && typeof object.color === 'string')) return false;

Expand Down
3 changes: 1 addition & 2 deletions src/pages/u/folder/[id].astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import LayoutSidebar from '@layouts/LayoutSidebar.astro';
import FileBrowser from '@components/files/FileBrowser.vue';
// @ts-ignore https://github.com/withastro/language-tools/issues/476
import { api, url } from '@lib/helpers';
import { ItemClass } from '@lib/items/items';
import { FolderClass } from '@lib/items/folders';
const { id } = Astro.params;
Expand All @@ -25,7 +24,7 @@ if (!folderResponse || folderResponse?.statusCode <= 400) {
}
// If the folder isn't a valid folder, redirect
if (!(ItemClass.isItem(folderResponse) && FolderClass.isFolder(folderResponse))) {
if (!FolderClass.isFolder(folderResponse)) {
return Astro.redirect(url('404'));
}
Expand Down

0 comments on commit 0a2623d

Please sign in to comment.