mirror of
https://gitea.smigz.com/smiggiddy/odin-codeprojects.git
synced 2025-07-17 06:40:36 -04:00
Compare commits
No commits in common. "5ab9f0b2c2e6f62b329044d73b30655b858f4dc3" and "269d7784ab9f79e1759070515a419be2fab3663b" have entirely different histories.
5ab9f0b2c2
...
269d7784ab
16 changed files with 103 additions and 443 deletions
133
.dockerignore
133
.dockerignore
|
@ -1,133 +0,0 @@
|
||||||
*.db
|
|
||||||
# Logs
|
|
||||||
logs
|
|
||||||
*.log
|
|
||||||
npm-debug.log*
|
|
||||||
yarn-debug.log*
|
|
||||||
yarn-error.log*
|
|
||||||
lerna-debug.log*
|
|
||||||
.pnpm-debug.log*
|
|
||||||
|
|
||||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
|
||||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
|
||||||
|
|
||||||
# Runtime data
|
|
||||||
pids
|
|
||||||
*.pid
|
|
||||||
*.seed
|
|
||||||
*.pid.lock
|
|
||||||
|
|
||||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
|
||||||
lib-cov
|
|
||||||
|
|
||||||
# Coverage directory used by tools like istanbul
|
|
||||||
coverage
|
|
||||||
*.lcov
|
|
||||||
|
|
||||||
# nyc test coverage
|
|
||||||
.nyc_output
|
|
||||||
|
|
||||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
|
||||||
.grunt
|
|
||||||
|
|
||||||
# Bower dependency directory (https://bower.io/)
|
|
||||||
bower_components
|
|
||||||
|
|
||||||
# node-waf configuration
|
|
||||||
.lock-wscript
|
|
||||||
|
|
||||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
|
||||||
build/Release
|
|
||||||
|
|
||||||
# Dependency directories
|
|
||||||
node_modules/
|
|
||||||
jspm_packages/
|
|
||||||
|
|
||||||
# Snowpack dependency directory (https://snowpack.dev/)
|
|
||||||
web_modules/
|
|
||||||
|
|
||||||
# TypeScript cache
|
|
||||||
*.tsbuildinfo
|
|
||||||
|
|
||||||
# Optional npm cache directory
|
|
||||||
.npm
|
|
||||||
|
|
||||||
# Optional eslint cache
|
|
||||||
.eslintcache
|
|
||||||
|
|
||||||
# Optional stylelint cache
|
|
||||||
.stylelintcache
|
|
||||||
|
|
||||||
# Microbundle cache
|
|
||||||
.rpt2_cache/
|
|
||||||
.rts2_cache_cjs/
|
|
||||||
.rts2_cache_es/
|
|
||||||
.rts2_cache_umd/
|
|
||||||
|
|
||||||
# Optional REPL history
|
|
||||||
.node_repl_history
|
|
||||||
|
|
||||||
# Output of 'npm pack'
|
|
||||||
*.tgz
|
|
||||||
|
|
||||||
# Yarn Integrity file
|
|
||||||
.yarn-integrity
|
|
||||||
|
|
||||||
# dotenv environment variable files
|
|
||||||
.env
|
|
||||||
.env.development.local
|
|
||||||
.env.test.local
|
|
||||||
.env.production.local
|
|
||||||
.env.local
|
|
||||||
|
|
||||||
# parcel-bundler cache (https://parceljs.org/)
|
|
||||||
.cache
|
|
||||||
.parcel-cache
|
|
||||||
|
|
||||||
# Next.js build output
|
|
||||||
.next
|
|
||||||
out
|
|
||||||
|
|
||||||
# Nuxt.js build / generate output
|
|
||||||
.nuxt
|
|
||||||
dist
|
|
||||||
|
|
||||||
# Gatsby files
|
|
||||||
.cache/
|
|
||||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
|
||||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
|
||||||
# public
|
|
||||||
|
|
||||||
# vuepress build output
|
|
||||||
.vuepress/dist
|
|
||||||
|
|
||||||
# vuepress v2.x temp and cache directory
|
|
||||||
.temp
|
|
||||||
.cache
|
|
||||||
|
|
||||||
# Docusaurus cache and generated files
|
|
||||||
.docusaurus
|
|
||||||
|
|
||||||
# Serverless directories
|
|
||||||
.serverless/
|
|
||||||
|
|
||||||
# FuseBox cache
|
|
||||||
.fusebox/
|
|
||||||
|
|
||||||
# DynamoDB Local files
|
|
||||||
.dynamodb/
|
|
||||||
|
|
||||||
# TernJS port file
|
|
||||||
.tern-port
|
|
||||||
|
|
||||||
# Stores VSCode versions used for testing VSCode extensions
|
|
||||||
.vscode-test
|
|
||||||
|
|
||||||
# yarn v2
|
|
||||||
.yarn/cache
|
|
||||||
.yarn/unplugged
|
|
||||||
.yarn/build-state.yml
|
|
||||||
.yarn/install-state.gz
|
|
||||||
.pnp.*
|
|
||||||
|
|
||||||
.DS_STORE
|
|
|
@ -25,23 +25,22 @@ model User {
|
||||||
}
|
}
|
||||||
|
|
||||||
model File {
|
model File {
|
||||||
id String @id @default(uuid())
|
id String @id @default(uuid())
|
||||||
name String @db.VarChar(255)
|
name String @db.VarChar(255)
|
||||||
url String
|
url String
|
||||||
size Int
|
size Int
|
||||||
mimetype String
|
mimetype String
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
modifiedAt DateTime @default("2020-03-19T14:21:00+02:00")
|
owner User? @relation(fields: [ownerId], references: [id])
|
||||||
owner User? @relation(fields: [ownerId], references: [id])
|
ownerId String?
|
||||||
ownerId String?
|
folder Folder? @relation(fields: [folderId], references: [id])
|
||||||
folder Folder? @relation(fields: [folderId], references: [id])
|
folderId String?
|
||||||
folderId String?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
model Folder {
|
model Folder {
|
||||||
id String @id @default(uuid())
|
id String @id @default(uuid())
|
||||||
name String @db.VarChar(255)
|
name String @db.VarChar(255)
|
||||||
createdAt DateTime @default(now())
|
creation_date DateTime @default(now())
|
||||||
modification_date DateTime @default(now())
|
modification_date DateTime @default(now())
|
||||||
File File[]
|
File File[]
|
||||||
owner User? @relation(fields: [owner_user_id], references: [id])
|
owner User? @relation(fields: [owner_user_id], references: [id])
|
||||||
|
|
|
@ -24,11 +24,6 @@ body {
|
||||||
-webkit-font-smoothing: antialiased;
|
-webkit-font-smoothing: antialiased;
|
||||||
}
|
}
|
||||||
|
|
||||||
html,
|
|
||||||
body {
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 6. Improve media defaults */
|
/* 6. Improve media defaults */
|
||||||
img,
|
img,
|
||||||
picture,
|
picture,
|
||||||
|
@ -139,32 +134,9 @@ input[type='file']:focus::file-selector-button {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main {
|
/* .file { */
|
||||||
display: flex;
|
/* opacity: 0; */
|
||||||
justify-content: center;
|
/* width: 0.1px; */
|
||||||
width: 100%;
|
/* height: 0.1px; */
|
||||||
}
|
/* position: absolute; */
|
||||||
|
/* } */
|
||||||
main > div {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
aside {
|
|
||||||
min-width: 250px;
|
|
||||||
padding: 1em;
|
|
||||||
}
|
|
||||||
.flex {
|
|
||||||
display: flex;
|
|
||||||
}
|
|
||||||
|
|
||||||
.directory-grid {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: 1fr 1fr 1fr;
|
|
||||||
}
|
|
||||||
|
|
||||||
.app {
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media screen and (max-width: 600px) {
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
const multer = require('multer');
|
const multer = require('multer');
|
||||||
|
const Db = require('../models/db');
|
||||||
const {
|
const {
|
||||||
uploadToStorage,
|
uploadFile,
|
||||||
mkDirectory,
|
mkDirectory,
|
||||||
getDirectoryContents,
|
getDirectoryContents,
|
||||||
createFileRecord,
|
getProperPath,
|
||||||
getFileMetaData,
|
|
||||||
editFile,
|
|
||||||
} = require('../services/fileService');
|
} = require('../services/fileService');
|
||||||
const { getFullUploadPath, formatBytes } = require('../utils/formatHelpers');
|
// const storage = multer.memoryStorage();
|
||||||
const { Prisma } = require('@prisma/client');
|
// const upload = multer({ storage: storage });
|
||||||
const upload = multer({ dest: '/tmp/odin/' });
|
const upload = multer({ dest: '/tmp/odin/' });
|
||||||
|
|
||||||
|
const db = new Db();
|
||||||
|
|
||||||
const createDirectory = async (req, res) => {
|
const createDirectory = async (req, res) => {
|
||||||
const { parentId, 'directory-name': directoryName } = req.body;
|
const { parentId, 'directory-name': directoryName } = req.body;
|
||||||
const referer = req.get('referer');
|
const referer = req.get('referer');
|
||||||
|
@ -27,45 +28,35 @@ const fileUpload = async (req, res) => {
|
||||||
const { folderId, folderName } = req.body;
|
const { folderId, folderName } = req.body;
|
||||||
const referer = req.get('referer');
|
const referer = req.get('referer');
|
||||||
|
|
||||||
|
let fullPath = await getProperPath(folderId);
|
||||||
|
fullPath =
|
||||||
|
fullPath === '/' ? `/${folderName}` : fullPath + `/${folderName}`;
|
||||||
|
|
||||||
|
const path = `${req.user.username}/${fullPath}/${req.file.originalname}`;
|
||||||
|
const file = {
|
||||||
|
name: req.file.originalname,
|
||||||
|
path: path,
|
||||||
|
folderId: folderId,
|
||||||
|
mimetype: req.file.mimetype,
|
||||||
|
size: req.file.size,
|
||||||
|
};
|
||||||
|
const data = {
|
||||||
|
name: req.file.originalname,
|
||||||
|
path: path,
|
||||||
|
data: req.file.filename,
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const path = await getFullUploadPath(
|
const supabaseResult = await uploadFile(data);
|
||||||
folderId,
|
if (supabaseResult.error === null) {
|
||||||
folderName,
|
const result = await db.file.createFile(req.user.id, file);
|
||||||
req.user.username,
|
console.log(result);
|
||||||
req.file.originalname,
|
|
||||||
);
|
|
||||||
|
|
||||||
const fileMetaData = {
|
|
||||||
name: req.file.originalname,
|
|
||||||
path: path,
|
|
||||||
folderId: folderId,
|
|
||||||
mimetype: req.file.mimetype,
|
|
||||||
size: req.file.size,
|
|
||||||
};
|
|
||||||
const data = {
|
|
||||||
name: req.file.originalname,
|
|
||||||
path: path,
|
|
||||||
data: req.file.filename,
|
|
||||||
};
|
|
||||||
|
|
||||||
const supabaseResult = await uploadToStorage(data);
|
|
||||||
if (!supabaseResult.error) {
|
|
||||||
// make sure the uploaded file and the db have the same ID
|
|
||||||
fileMetaData.id = supabaseResult.data.id;
|
|
||||||
const result = await createFileRecord(req.user.id, fileMetaData);
|
|
||||||
if (result instanceof Prisma.PrismaClientKnownRequestError) {
|
|
||||||
// if user uploads the samefile name, just overwrite it
|
|
||||||
await editFile(fileMetaData);
|
|
||||||
}
|
|
||||||
res.redirect(referer);
|
|
||||||
} else {
|
|
||||||
console.error(supabaseResult.error);
|
|
||||||
res.status(500).redirect(referer);
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
res.status(500).redirect(referer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res.redirect(referer);
|
||||||
};
|
};
|
||||||
|
|
||||||
const directoryContents = async (req, res) => {
|
const directoryContents = async (req, res) => {
|
||||||
|
@ -83,31 +74,6 @@ const directoryContents = async (req, res) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getFileData = async (req, res) => {
|
const getFiles = (req, res) => {};
|
||||||
const { fileId } = req.query;
|
|
||||||
|
|
||||||
try {
|
module.exports = { createDirectory, upload, fileUpload, directoryContents };
|
||||||
const file = await getFileMetaData(fileId);
|
|
||||||
file.size = formatBytes(file.size);
|
|
||||||
|
|
||||||
res.render('partials/fileInfo', {
|
|
||||||
file: file,
|
|
||||||
pageTitle: 'FileUpload - File Details',
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
res.redirect('/');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const editFilePost = async (req, res) => {
|
|
||||||
const { id, name, url, modifiedAt, mimetype } = req.body;
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
createDirectory,
|
|
||||||
upload,
|
|
||||||
fileUpload,
|
|
||||||
directoryContents,
|
|
||||||
getFileData,
|
|
||||||
};
|
|
||||||
|
|
|
@ -2,10 +2,9 @@ const {
|
||||||
getDirectoryContents,
|
getDirectoryContents,
|
||||||
getParentDirectories,
|
getParentDirectories,
|
||||||
} = require('../services/fileService');
|
} = require('../services/fileService');
|
||||||
const { formatBytes } = require('../utils/formatHelpers');
|
|
||||||
|
|
||||||
const indexGet = async (req, res) => {
|
const indexGet = async (req, res) => {
|
||||||
if (req.isAuthenticated()) {
|
if (req.user) {
|
||||||
res.redirect(`/fs/${req.user.username}/${req.user.rootDirectoryId}`);
|
res.redirect(`/fs/${req.user.username}/${req.user.rootDirectoryId}`);
|
||||||
// if unauthenticated redirect
|
// if unauthenticated redirect
|
||||||
} else {
|
} else {
|
||||||
|
@ -28,7 +27,6 @@ const userDirectoryNavigation = async (req, res) => {
|
||||||
folder: { id: directoryId, name: dirContents.name },
|
folder: { id: directoryId, name: dirContents.name },
|
||||||
directoryListing: dirContents,
|
directoryListing: dirContents,
|
||||||
parentDirectories: parentDirectories,
|
parentDirectories: parentDirectories,
|
||||||
formatBytes: formatBytes,
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ passport.deserializeUser(async (id, done) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const loggedIn = function (req, res, next) {
|
const loggedIn = function (req, res, next) {
|
||||||
if (!req.isAuthenticated()) res.redirect('/');
|
if (!req.user) res.redirect('/');
|
||||||
next();
|
next();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const { Prisma, PrismaClient } = require('@prisma/client');
|
const { PrismaClient } = require('@prisma/client');
|
||||||
|
|
||||||
class File {
|
class File {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -87,6 +87,8 @@ class File {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getDirectoriesByUser() {}
|
||||||
|
|
||||||
async createFile(userId, file) {
|
async createFile(userId, file) {
|
||||||
try {
|
try {
|
||||||
const result = await this.prisma.file.create({
|
const result = await this.prisma.file.create({
|
||||||
|
@ -97,48 +99,6 @@ class File {
|
||||||
url: file.path,
|
url: file.path,
|
||||||
folderId: file.folderId,
|
folderId: file.folderId,
|
||||||
ownerId: userId,
|
ownerId: userId,
|
||||||
id: file.id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
return result;
|
|
||||||
} catch (e) {
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async editFile(file) {
|
|
||||||
const data = await this.prisma.file.update({
|
|
||||||
where: { id: file.id },
|
|
||||||
data: {
|
|
||||||
name: file.name,
|
|
||||||
size: file.size,
|
|
||||||
mimetype: file.mimetype,
|
|
||||||
url: file.path,
|
|
||||||
modifiedAt: new Date(),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
async deleteFile(userId, fileId) {
|
|
||||||
try {
|
|
||||||
const result = await this.prisma.file.delete({
|
|
||||||
data: {
|
|
||||||
id: fileId,
|
|
||||||
ownerId: userId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
return result;
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
async getFileMetaData(fileId) {
|
|
||||||
try {
|
|
||||||
const result = await this.prisma.file.findUnique({
|
|
||||||
where: {
|
|
||||||
id: fileId,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -11,6 +11,5 @@ fileRouter.post(
|
||||||
);
|
);
|
||||||
fileRouter.post('/directory', loggedIn, fileController.createDirectory);
|
fileRouter.post('/directory', loggedIn, fileController.createDirectory);
|
||||||
fileRouter.get('/directory', loggedIn, fileController.directoryContents);
|
fileRouter.get('/directory', loggedIn, fileController.directoryContents);
|
||||||
fileRouter.get('/file', loggedIn, fileController.getFileData);
|
|
||||||
|
|
||||||
module.exports = fileRouter;
|
module.exports = fileRouter;
|
||||||
|
|
|
@ -8,14 +8,6 @@ const supabase = createClient(supabaseUrl, supabaseKey);
|
||||||
|
|
||||||
const db = new Db();
|
const db = new Db();
|
||||||
|
|
||||||
async function createFileRecord(userId, fileData) {
|
|
||||||
return await db.file.createFile(userId, fileData);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function editFile(file) {
|
|
||||||
return await db.file.editFile(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getDirectoryContents(directoryId, userId) {
|
async function getDirectoryContents(directoryId, userId) {
|
||||||
return await db.file.getDirectoryContents(directoryId, userId);
|
return await db.file.getDirectoryContents(directoryId, userId);
|
||||||
}
|
}
|
||||||
|
@ -24,10 +16,10 @@ async function getParentDirectories(directoryId) {
|
||||||
return await db.file.getParentFolders(directoryId);
|
return await db.file.getParentFolders(directoryId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function uploadToStorage(file) {
|
async function uploadFile(file) {
|
||||||
const { data, error } = await supabase.storage
|
const { data, error } = await supabase.storage
|
||||||
.from('odin')
|
.from('odin')
|
||||||
.upload(file.path, file.data, { upsert: true });
|
.upload(file.path, file.data);
|
||||||
|
|
||||||
return { data: data, error: error };
|
return { data: data, error: error };
|
||||||
}
|
}
|
||||||
|
@ -60,18 +52,11 @@ async function getProperPath(directoryId) {
|
||||||
return directories.join('/');
|
return directories.join('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getFileMetaData(fileId) {
|
|
||||||
return await db.file.getFileMetaData(fileId);
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
createFileRecord,
|
uploadFile,
|
||||||
editFile,
|
|
||||||
uploadToStorage,
|
|
||||||
mkDirectory,
|
mkDirectory,
|
||||||
getParentDirectories,
|
getParentDirectories,
|
||||||
getDirectoryContents,
|
getDirectoryContents,
|
||||||
getProperPath,
|
getProperPath,
|
||||||
rmDirectory,
|
rmDirectory,
|
||||||
getFileMetaData,
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
const { getProperPath } = require('../services/fileService');
|
|
||||||
|
|
||||||
const getFullUploadPath = async (folderId, folderName, username, filename) => {
|
|
||||||
let fullPath = await getProperPath(folderId);
|
|
||||||
fullPath = fullPath === '/' ? `${folderName}` : fullPath + `/${folderName}`;
|
|
||||||
|
|
||||||
return `${username}/${fullPath}/${filename}`;
|
|
||||||
};
|
|
||||||
|
|
||||||
const formatBytes = (bytes, decimals = 2) => {
|
|
||||||
if (!+bytes) return '-';
|
|
||||||
|
|
||||||
const k = 1024;
|
|
||||||
const dm = decimals < 0 ? 0 : decimals;
|
|
||||||
const sizes = [
|
|
||||||
'Bytes',
|
|
||||||
'KiB',
|
|
||||||
'MiB',
|
|
||||||
'GiB',
|
|
||||||
'TiB',
|
|
||||||
'PiB',
|
|
||||||
'EiB',
|
|
||||||
'ZiB',
|
|
||||||
'YiB',
|
|
||||||
];
|
|
||||||
|
|
||||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
||||||
|
|
||||||
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = { formatBytes, getFullUploadPath };
|
|
|
@ -1,33 +1,20 @@
|
||||||
<%- include('partials/header') %>
|
<%- include('partials/header') %>
|
||||||
<body>
|
<body>
|
||||||
<% if(currentUser) { %>
|
<% if(currentUser) { %>
|
||||||
<div class="container flex app">
|
<p> Hello <%= currentUser.username %> </p>
|
||||||
<aside class="nav">
|
<a href="/auth/logout">sign out</a>
|
||||||
<p> Hello <%= currentUser.username %> </p>
|
<%- include('partials/fileUpload') %>
|
||||||
<a href="/auth/logout">sign out</a>
|
<%- include('partials/parentDirectories') %>
|
||||||
<%- include('partials/newDirectory') %>
|
<%- include('partials/directoryListing') %>
|
||||||
<%- include('partials/fileUpload') %>
|
|
||||||
</aside>
|
|
||||||
<main>
|
|
||||||
<div class="container">
|
|
||||||
|
|
||||||
|
|
||||||
<%- include('partials/parentDirectories') %>
|
|
||||||
<%- include('partials/directoryListing') %>
|
|
||||||
</div>
|
|
||||||
</main>
|
|
||||||
</div>
|
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
<main>
|
<form action="/auth/login" method="post">
|
||||||
<form action="/auth/login" method="post">
|
<label for="username">Username</label>
|
||||||
<label for="username">Username</label>
|
<input type="text" name="username">
|
||||||
<input type="text" name="username">
|
<label for="password">Password</label>
|
||||||
<label for="password">Password</label>
|
<input type="password" name="password" id="password">
|
||||||
<input type="password" name="password" id="password">
|
<button type="submit">Submit</button>
|
||||||
<button type="submit">Submit</button>
|
<a href="/auth/register">Click here to register</a>
|
||||||
<a href="/auth/register">Click here to register</a>
|
</form>
|
||||||
</form>
|
|
||||||
</main>
|
|
||||||
|
|
||||||
|
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
|
@ -1,40 +1,12 @@
|
||||||
<section class="container directory-listing">
|
<div class="container">
|
||||||
<div class="directory-grid">
|
<h2> Folders</h2>
|
||||||
<div class="col file-name heading directory__grid_heading">
|
<ul>
|
||||||
<p class="title__heading">Name</p>
|
<% directoryListing.Directories.forEach(d => { %>
|
||||||
</div>
|
<li><a href="/fs/<%= currentUser.username %>/<%= d.id %>"> <%= d.name %> </a></li>
|
||||||
|
<% }); %>
|
||||||
<div class="col file-size directory__grid__heading">
|
</ul>
|
||||||
<p class="title__heading">Size</p>
|
<h2> Files: </h2>
|
||||||
</div>
|
<% directoryListing.File.forEach(f => { %>
|
||||||
|
<p> <%= f.name %> <%= f.id %></p>
|
||||||
<div class="col file-modified directory__grid__heading">
|
<% }); %>
|
||||||
<p class="title__heading">Created</p>
|
</div>
|
||||||
</div>
|
|
||||||
<!-- Combined loop for both directories and files -->
|
|
||||||
<%
|
|
||||||
const renderItem = (item, isDirectory) => {
|
|
||||||
%>
|
|
||||||
<div class="col file-name">
|
|
||||||
<% if (isDirectory) { %>
|
|
||||||
d <a href="/fs/<%= currentUser.username %>/<%= item.id %>"><%= item.name %></a> /
|
|
||||||
<% } else { %>
|
|
||||||
- <%= item.name %> <a href="/file/file?fileId=<%= item.id %>">Details</a>
|
|
||||||
<% } %>
|
|
||||||
</div>
|
|
||||||
<div class="col file-size">
|
|
||||||
<p><%= formatBytes(item?.size) %></p>
|
|
||||||
</div>
|
|
||||||
<div class="col file-modified">
|
|
||||||
<p><%= item?.createdAt %></p>
|
|
||||||
</div>
|
|
||||||
<% }; %>
|
|
||||||
|
|
||||||
<!-- Render directories -->
|
|
||||||
<% directoryListing.Directories.forEach(d => renderItem(d, true)); %>
|
|
||||||
|
|
||||||
<!-- Render files -->
|
|
||||||
<% directoryListing.File.forEach(f => renderItem(f, false)); %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
<div class="container">
|
|
||||||
|
|
||||||
<div class="file-metadata">
|
|
||||||
<h2>File: <%= file.name %> </h2>
|
|
||||||
<p>Size: <%= file.size %> </p>
|
|
||||||
<p>Created At: <%= file.createdAt %></p>
|
|
||||||
<p>Modified At: <%= file?.modifiedAt %></p>
|
|
||||||
</div>
|
|
||||||
<a href="/fs/<%= currentUser.username %>/<%= file.folderId %>">Back</a>
|
|
||||||
</div>
|
|
|
@ -1,12 +1,18 @@
|
||||||
<section class="file-upload">
|
<form action="/file" method="post" enctype="multipart/form-data">
|
||||||
<h2 class="h2-heading">New upload</h2>
|
<div class="container file-upload">
|
||||||
<form action="/file" method="post" enctype="multipart/form-data">
|
<input type="file" name="fileUpload" id="fileUpload" class="file" required>
|
||||||
<div class="container file-upload">
|
<input type="hidden" name="folderId" value=<%= folder.id %>>
|
||||||
<input type="file" name="fileUpload" id="fileUpload" class="file" required>
|
<input type="hidden" name="folderName" value=<%= folder.name %>>
|
||||||
<input type="hidden" name="folderId" value=<%= folder.id %>>
|
<button type="submit">Upload</button>
|
||||||
<input type="hidden" name="folderName" value=<%= folder.name %>>
|
</div>
|
||||||
<button type="submit" class="btn">Upload</button>
|
</form>
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
|
|
||||||
|
<form action="/file/directory" method="post">
|
||||||
|
<div class="container">
|
||||||
|
<label for="directory-name">Directory Name:</label>
|
||||||
|
<input type="text" name="directory-name" placeholder="" required>
|
||||||
|
<input type="hidden" name="parentId" value=<%= folder.id %>>
|
||||||
|
<button>Create Directory</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
<form action="/file/directory" method="post">
|
|
||||||
<div class="container">
|
|
||||||
<div class="form-item">
|
|
||||||
<label for="directory-name">Directory Name:</label>
|
|
||||||
<input type="text" name="directory-name" placeholder="" required>
|
|
||||||
</div>
|
|
||||||
<input type="hidden" name="parentId" value=<%= folder.id %>>
|
|
||||||
<button class="btn">Create Directory</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
|
@ -1,8 +1,9 @@
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<p class="directory-path">
|
<p>
|
||||||
<% parentDirectories.forEach(d => { %>
|
<% parentDirectories.forEach(d => { %>
|
||||||
<a href="/fs/<%= currentUser.username %>/<%= d.id %>"><%= d.name %></a><span> /</span>
|
<a href="/fs/<%= currentUser.username %>/<%= d.id %>"><%= d.name %></a><span> /</span>
|
||||||
|
|
||||||
<% }); %>
|
<% }); %>
|
||||||
<span class="current-directory"> <%= directoryListing.name %></span>
|
<span> <%= directoryListing.name %></span>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue