Skip to content

Commit

Permalink
fix invitation, archive lookup feat
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexRoehm committed Dec 31, 2022
1 parent 8c13ce6 commit 09036ca
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ tmp
.tmp
settings.json
docker/runtime
docker/log
docker/log
archiv
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ public/s
public-docker
org.*
settings.json
docker-compose.yml
docker-compose.yml
docker/runtime
archiv
3 changes: 2 additions & 1 deletion .nuxtignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public-docker
tmp
temp
data
docker
docker
archiv
3 changes: 2 additions & 1 deletion base/Constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const VERSION ="v1.0.3";
export const VERSION ="v1.0.4";
export const DATA_PATH ="public";
export const ARCHIV_PATH ="archiv";
export const PUBLIC_RESOURCES = 'public';
export const FEED_SLUG = '/s/feed/';
export const SERVER_IMG_PATH = '/s/covers/';
Expand Down
2 changes: 1 addition & 1 deletion pages/admin/setpassword.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const submit = async () => {
const success = await useAuth().changePassword(currentuser.value.username, password1.value, passwordOld.value)
if (success) {
isDone.value = true
var url = router.options.history.state.back as string;
var url = "/admin"
router.push({
path: url,
query: { msg: 'login.passwordset' }
Expand Down
13 changes: 13 additions & 0 deletions server/api/lookuparchiv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import fs from 'fs'
import {sendError} from 'h3'
import { ARCHIV_PATH } from '~~/base/Constants';
import { findFile } from '../findFilePath';

export default defineEventHandler( async (event) => {
const query = getQuery(event);
if (query.name) {
return { path: findFile(query.name, ARCHIV_PATH) }
} else
sendError(event, createError("No path or filename provided"))
return { path:"" }
})
19 changes: 19 additions & 0 deletions server/findFilePath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import fs from 'fs'
import path from 'path'

export function findFile(name: string, path: string) : string {
const dirs = [path]
while (dirs.length>0) {
const currentDir = dirs.pop()
const items = fs.readdirSync(currentDir);
for (const item of items) {
if (!(fs.lstatSync(`${currentDir}/${item}`)).isDirectory()) {
if (item===name)
return `${currentDir}/${item}`
} else
dirs.push(`${currentDir}/${item}`)
}
}
return ""
}

12 changes: 8 additions & 4 deletions server/middleware/authentication.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import UrlPattern from "url-pattern"
import { sendError } from "h3"
import { decodeAccessToken, decodeRefreshToken } from "../jwt"
import { decodeAccessToken, decodeRefreshToken, decodeUrlToken } from "../jwt"
import { getUserById } from "../services/userService"
import { d } from "vitest/dist/index-ea17aa0c"

Expand All @@ -11,7 +11,7 @@ export default defineEventHandler(async (event) => {
const login = new UrlPattern('/api/auth/login')

const isHandledByThisMiddleware =
(event.req.method != 'GET' && !login.match(event.node.req.url)) ||
(event.node.req.method != 'GET' && !login.match(event.node.req.url)) ||
endpoints.some(endopoint => {
const pattern = new UrlPattern(endopoint)
return pattern.match(event.node.req.url)
Expand All @@ -31,12 +31,16 @@ export default defineEventHandler(async (event) => {
cookie = event.node.req.headers['Cookie'] as string
const match = cookie?.match(regex)
decoded = decodeRefreshToken((match?.length>1?match[1]:""))
if (!decoded) {
}
if (!decoded) {
const { token } = await readBody(event);
if (token)
decoded = decodeUrlToken(token)
if (!decoded)
return sendError(event, createError({
statusCode: 401,
statusMessage: 'Unauthorized'
}))
}
}

try {
Expand Down
Empty file added tests/testdata/dir1/a
Empty file.
Empty file added tests/testdata/dir1/b.txt
Empty file.
Empty file.
21 changes: 21 additions & 0 deletions tests/unit/findFilePath.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { describe, expect, it } from "vitest";
import { findFile } from "../../server/findFilePath";

describe("DetailValidation", async () => {
it.skip("Epmty dir returns empty string", () => {
const actual = findFile("a", "tests/testdata/empty")
expect(actual).toBe("");
})
it("File in sub dir returns its path", () => {
const actual = findFile("b.txt", "tests/testdata")
expect(actual).toBe("tests/testdata/dir1/b.txt");
})
it("File in deeply nested sub dir returns its path", () => {
const actual = findFile("c.txt", "tests/testdata")
expect(actual).toBe("tests/testdata/dir2/dir21/dir211/c.txt");
})
it("File not in deeply nested sub dir empty string", () => {
const actual = findFile("ct", "tests/testdata")
expect(actual).toBe("");
})
})

0 comments on commit 09036ca

Please sign in to comment.