feat: product barcode pdf resize
This commit is contained in:
		@@ -1,6 +1,5 @@
 | 
			
		||||
from abc import abstractmethod
 | 
			
		||||
 | 
			
		||||
from fastapi import UploadFile
 | 
			
		||||
from typing import BinaryIO
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class BaseImagesUploader:
 | 
			
		||||
@@ -18,5 +17,5 @@ class BaseImagesUploader:
 | 
			
		||||
        pass
 | 
			
		||||
 | 
			
		||||
    @abstractmethod
 | 
			
		||||
    async def upload(self, upload_file: UploadFile) -> str:
 | 
			
		||||
        pass
 | 
			
		||||
    async def upload(self, file: BinaryIO, filename: str) -> str:
 | 
			
		||||
        pass
 | 
			
		||||
 
 | 
			
		||||
@@ -1,11 +1,10 @@
 | 
			
		||||
from pathlib import Path
 | 
			
		||||
from typing import BinaryIO
 | 
			
		||||
from uuid import uuid4
 | 
			
		||||
 | 
			
		||||
from aioshutil import copyfileobj
 | 
			
		||||
from fastapi import UploadFile
 | 
			
		||||
 | 
			
		||||
from barcodes.images_uploader.base import BaseImagesUploader
 | 
			
		||||
from barcodes.pdf import PDFGenerator
 | 
			
		||||
from constants import APP_PATH, API_ROOT
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -29,10 +28,10 @@ class BarcodeImagesUploader(BaseImagesUploader):
 | 
			
		||||
        if file_location.exists():
 | 
			
		||||
            file_location.unlink()
 | 
			
		||||
 | 
			
		||||
    async def upload(self, upload_file: UploadFile) -> str:
 | 
			
		||||
        filename = str(uuid4()) + '.' + upload_file.filename.split('.')[-1]
 | 
			
		||||
    async def upload(self, file: BinaryIO, filename: str) -> str:
 | 
			
		||||
        filename = str(uuid4()) + '.' + filename.split('.')[-1]
 | 
			
		||||
        file_location = self.storage_path / filename
 | 
			
		||||
        with open(file_location, 'wb') as buffer:
 | 
			
		||||
            await copyfileobj(upload_file.file, buffer)
 | 
			
		||||
            await copyfileobj(file, buffer)
 | 
			
		||||
 | 
			
		||||
        return filename
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user