Skip to content

Commit

Permalink
Merge pull request #352 from blinko-space/refactor-resouce
Browse files Browse the repository at this point in the history
fix: build issue
  • Loading branch information
blinko-space authored Dec 21, 2024
2 parents 1084a67 + 169e3b3 commit e045cfe
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 35 deletions.
2 changes: 1 addition & 1 deletion app/api/file/[...filename]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const GET = async (req: NextRequest, { params }: any) => {


const sanitizedPath = fullPath.replace(/^[./\\]+/, '');
const filePath = path.join(process.cwd(), UPLOAD_FILE_PATH, sanitizedPath);
const filePath = path.join(UPLOAD_FILE_PATH, sanitizedPath);

try {
if (isImage(fullPath) && needThumbnail) {
Expand Down
12 changes: 0 additions & 12 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ module.exports = withPWA({
];
},
webpack: (config, { dev,isServer }) => {
if (dev) {
config.watchOptions = {
poll: 1000,
aggregateTimeout: 300,
}
}
config.experiments = { ...config.experiments, topLevelAwait: true };
if (!isServer) {
config.resolve.fallback = {
Expand All @@ -65,12 +59,6 @@ module.exports = withPWA({
}
return config;
},
experimental: {
turbotrace: {
memoryLimit: process.env.CI ? 4096 : 8192,
logLevel: 'bug',
}
},
outputFileTracing: isVercel? false : true,
reactStrictMode: isProduction? true : false,
swcMinify: true,
Expand Down
3 changes: 2 additions & 1 deletion src/components/BlinkoResource/ResourceContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { helper } from "@/lib/helper";
import { showTipsDialog } from "../Common/TipsDialog";
import { PromiseCall } from "@/store/standard/PromiseState";
import { ToastPlugin } from "@/store/module/Toast/Toast";
import { DialogStandaloneStore } from "@/store/module/DialogStandalone";

const MenuItem = ({ icon, label, className = '' }: { icon: string; label: string; className?: string }) => (
<div className={`flex items-center gap-2 ${className}`}>
Expand Down Expand Up @@ -132,7 +133,7 @@ export const ResourceContextMenu = observer(({ onTrigger }: ResourceContextMenuP
isFolder: false
}));
}
RootStore.Get(DialogStore).close();
RootStore.Get(DialogStandaloneStore).close();
resourceStore.refreshTicker++;
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/server/plugins/ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import dayjs from 'dayjs';
//https://js.langchain.com/docs/introduction/
//https://smith.langchain.com/onboarding
//https://js.langchain.com/docs/tutorials/qa_chat_history
const FaissStorePath = path.join(process.cwd(), FAISS_PATH);
const FaissStorePath = path.join(FAISS_PATH);

export class AiService {
static async loadFileContent(filePath: string): Promise<string> {
Expand Down Expand Up @@ -215,7 +215,7 @@ export class AiService {

static async *rebuildEmbeddingIndex({ force = false }: { force?: boolean }): AsyncGenerator<ProgressResult & { progress?: { current: number, total: number } }, void, unknown> {
if (force) {
const faissPath = path.join(process.cwd(), FAISS_PATH)
const faissPath = path.join(FAISS_PATH)
fs.rmSync(faissPath, { recursive: true, force: true })
}
const notes = await prisma.notes.findMany({
Expand Down
2 changes: 1 addition & 1 deletion src/server/plugins/ai/openAIModelProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export abstract class AiBaseModelPrivider {


public async VectorStore(): Promise<FaissStore> {
const FaissStorePath = path.join(process.cwd(), FAISS_PATH)
const FaissStorePath = path.join(FAISS_PATH)
try {
return await FaissStore.load(
FaissStorePath,
Expand Down
35 changes: 17 additions & 18 deletions src/server/plugins/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ export class FileService {
}

try {
const filePath = path.join(process.cwd(), `${UPLOAD_FILE_PATH}${customPath}` + filename);
const filePath = path.join(`${UPLOAD_FILE_PATH}${customPath}` + filename);
await fs.access(filePath);
return this.writeFileSafe(baseName, extension, buffer, attempt + 1);
} catch (error) {
const filePath = path.join(process.cwd(), `${UPLOAD_FILE_PATH}${customPath}` + filename);
const filePath = path.join(`${UPLOAD_FILE_PATH}${customPath}` + filename);
await fs.mkdir(path.dirname(filePath), { recursive: true });
//@ts-ignore
await writeFile(filePath, buffer);
Expand Down Expand Up @@ -106,7 +106,7 @@ export class FileService {
await prisma.attachments.delete({ where: { id: attachmentPath.id } })
}
} else {
const filepath = path.join(process.cwd(), UPLOAD_FILE_PATH, api_attachment_path.replace('/api/file/', ""));
const filepath = path.join(UPLOAD_FILE_PATH, api_attachment_path.replace('/api/file/', ""));
const attachmentPath = await prisma.attachments.findFirst({ where: { path: api_attachment_path } })
if (attachmentPath) {
await prisma.attachments.delete({ where: { id: attachmentPath.id } })
Expand Down Expand Up @@ -182,7 +182,7 @@ export class FileService {
customPath = customPath.endsWith('/') ? customPath : customPath + '/';
}

const fullPath = path.join(process.cwd(), UPLOAD_FILE_PATH, customPath, timestampedFileName);
const fullPath = path.join(UPLOAD_FILE_PATH, customPath, timestampedFileName);
await fs.mkdir(path.dirname(fullPath), { recursive: true });

const writeStream = createWriteStream(fullPath);
Expand Down Expand Up @@ -231,7 +231,7 @@ export class FileService {
throw new Error(`Failed to rename file in S3: ${error.message}`);
}
} else {
const oldFilePath = path.join(process.cwd(), UPLOAD_FILE_PATH, oldPath.replace('/api/file/', ''));
const oldFilePath = path.join(UPLOAD_FILE_PATH, oldPath.replace('/api/file/', ''));
const newFilePath = path.join(path.dirname(oldFilePath), newName);

await fs.rename(oldFilePath, newFilePath);
Expand Down Expand Up @@ -277,8 +277,8 @@ export class FileService {
throw new Error(`Failed to move file in S3: ${error.message}`);
}
} else {
const oldFilePath = path.join(process.cwd(), UPLOAD_FILE_PATH, oldPath.replace('/api/file/', ''));
const newFilePath = path.join(process.cwd(), UPLOAD_FILE_PATH, newPath.replace('/api/file/', ''));
const oldFilePath = path.join(UPLOAD_FILE_PATH, oldPath.replace('/api/file/', ''));
const newFilePath = path.join(UPLOAD_FILE_PATH, newPath.replace('/api/file/', ''));

await fs.mkdir(path.dirname(newFilePath), { recursive: true });
await fs.rename(oldFilePath, newFilePath);
Expand All @@ -291,17 +291,16 @@ export class FileService {
await fs.rmdir(oldDir);

let parentDir = path.dirname(oldDir);
const uploadPath = path.join(process.cwd(), UPLOAD_FILE_PATH);

// while (parentDir !== uploadPath) {
// const parentFiles = await fs.readdir(parentDir);
// if (parentFiles.length === 0) {
// await fs.rmdir(parentDir);
// parentDir = path.dirname(parentDir);
// } else {
// break;
// }
// }
const uploadPath = path.join(UPLOAD_FILE_PATH);
while (parentDir !== uploadPath) {
const parentFiles = await fs.readdir(parentDir);
if (parentFiles.length === 0) {
await fs.rmdir(parentDir);
parentDir = path.dirname(parentDir);
} else {
break;
}
}
}
} catch (error) {
console.error('Failed to cleanup old directories:', error);
Expand Down

0 comments on commit e045cfe

Please sign in to comment.