File size: 1,953 Bytes
0b8f50d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from slowapi import Limiter
from config import ACCESS_RATE
from fastapi import APIRouter, File, Request, Depends, HTTPException, UploadFile
from fastapi.security import HTTPBearer
from slowapi import Limiter
from slowapi.util import get_remote_address
from io import BytesIO
from .controller import process_image_ela , verify_token,process_fft_image, process_meta_image
import requests
router = APIRouter()
limiter = Limiter(key_func=get_remote_address)
security = HTTPBearer()



@router.post("/ela")
@limiter.limit(ACCESS_RATE)
async def detect_ela(request:Request,file: UploadFile = File(...), quality: int = 90 ,token: str = Depends(verify_token)):
    # Check file extension
    allowed_types = ["image/jpeg", "image/png"]

    if file.content_type not in allowed_types:
        raise HTTPException(
            status_code=400,
            detail="Unsupported file type. Only JPEG and PNG images are allowed."
        )
    
    content = await file.read()
    result = await process_image_ela(content, quality)
    return result

@router.post("/fft")
@limiter.limit(ACCESS_RATE)
async def detect_fft(request:Request,file:UploadFile =File(...),threshold:float=0.95,token:str=Depends(verify_token)):
    if file.content_type not in ["image/jpeg", "image/png"]:
        raise HTTPException(status_code=400, detail="Unsupported image type.")
    
    content = await file.read()
    result = await process_fft_image(content,threshold)
    return result

@router.post("/meta")
@limiter.limit(ACCESS_RATE)
async def detect_meta(request:Request,file:UploadFile=File(...),token:str=Depends(verify_token)):
    if file.content_type not in ["image/jpeg", "image/png"]:
        raise HTTPException(status_code=400, detail="Unsupported image type.")
    content = await file.read()    
    result = await process_meta_image(content)
    return result
@router.post("/health")
@limiter.limit(ACCESS_RATE)
def heath(request:Request):
    return {"status":"ok"}