This repository was archived by the owner on Jan 27, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +15
-9
lines changed Expand file tree Collapse file tree 5 files changed +15
-9
lines changed Original file line number Diff line number Diff line change @@ -19,3 +19,5 @@ You can configure a few things by editing the file `src/config/index.tsx`.
19
19
- ` DIR ` - The directory to watch.
20
20
- ` MAX_IMAGES ` - How many images to request. Default 10.
21
21
- ` POLL_INTERVAL ` - How often should the frontend look for updates. Default 5 seconds.
22
+ - ` FILE_EXTENSION ` - The filetypes supported. Default ` png ` .
23
+ - ` FILE_MIME ` - The file mime type. Default ` image/png ` .
Original file line number Diff line number Diff line change 1
1
export const DIR = `D:\\stable-diffusion-webui\\outputs\\txt2img-images` ;
2
2
export const MAX_IMAGES = 10 ;
3
3
export const POLL_INTERVAL = 5 * 1000 ;
4
+ export const FILE_EXTENSION = "png" ;
5
+ export const FILE_MIME = "image/png" ;
Original file line number Diff line number Diff line change 1
1
import "@/styles/globals.css" ;
2
2
import type { AppProps } from "next/app" ;
3
3
4
- function MyApp ( { Component, pageProps } : AppProps ) {
4
+ const MyApp = ( { Component, pageProps } : AppProps ) => {
5
5
return < Component { ...pageProps } /> ;
6
- }
6
+ } ;
7
7
8
8
export default MyApp ;
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import fs from "fs";
3
3
4
4
import type { NextApiRequest , NextApiResponse } from "next" ;
5
5
6
- import { DIR } from "@/config" ;
6
+ import { DIR , FILE_MIME } from "@/config" ;
7
7
8
8
type QueryData = {
9
9
image : string ;
@@ -25,7 +25,7 @@ export default async function handler(
25
25
const stat = fs . statSync ( filePath ) ;
26
26
27
27
res . writeHead ( 200 , {
28
- "Content-Type" : "image/png" ,
28
+ "Content-Type" : FILE_MIME ,
29
29
"Content-Length" : stat . size ,
30
30
} ) ;
31
31
Original file line number Diff line number Diff line change
1
+ import path from "path" ;
1
2
import fs from "fs" ;
2
3
3
4
import type { NextApiRequest , NextApiResponse } from "next" ;
4
5
5
- import { DIR , MAX_IMAGES } from "@/config" ;
6
+ import { DIR , FILE_EXTENSION , MAX_IMAGES } from "@/config" ;
6
7
7
8
type Data = {
8
9
images : string [ ] ;
@@ -15,19 +16,20 @@ export default async function handler(
15
16
const files = await fs . promises . readdir ( DIR ) ;
16
17
17
18
const images = files
18
- . map ( function ( fileName ) {
19
+ . map ( ( fileName ) => {
19
20
const stat = fs . statSync ( DIR + "/" + fileName ) ;
20
21
return {
21
22
name : fileName ,
22
23
time : stat . mtime . getTime ( ) ,
23
24
} ;
24
25
} )
25
- . sort ( function ( a , b ) {
26
+ . sort ( ( a , b ) => {
26
27
return a . time - b . time ;
27
28
} )
29
+ . filter ( ( f ) => path . extname ( f . name ) . toLowerCase ( ) === `.${ FILE_EXTENSION } ` )
28
30
. reverse ( )
29
- . map ( function ( v ) {
30
- return v . name ;
31
+ . map ( ( f ) => {
32
+ return f . name ;
31
33
} ) ;
32
34
33
35
res . status ( 200 ) . json ( { images : images . slice ( 0 , MAX_IMAGES ) } ) ;
You can’t perform that action at this time.
0 commit comments