Mika Scraper / TranslateImageClient
Class: TranslateImageClient
Defined in: src/_other-scraper/translate-image.ts:23
The TranslateImageClient class provides methods for interacting with the TranslateImage.app services. It supports uploading and translating e-commerce product images, general OCR images, and manga panels.
Constructors
Constructor
new TranslateImageClient():
TranslateImageClient
Returns
An instance of TranslateImageClient.
Methods
getUploadCredentials()
getUploadCredentials(
fileName,fileType):Promise<UploadCredentials>
Defined in: src/_other-scraper/translate-image.ts:53
Requests temporary credentials for uploading an image to Aliyun OSS.
Parameters
fileName
string (default: 'image.jpg')
The name of the file to upload.
fileType
string (default: 'image/jpeg')
The MIME type of the file.
Returns
Promise<UploadCredentials>
A promise that resolves to an UploadCredentials object.
Throws
Throws an error if credentials cannot be retrieved.
Example
const creds = await client.getUploadCredentials('product.png');uploadToAliyunOSS()
uploadToAliyunOSS(
localPath,credentials):Promise<string>
Defined in: src/_other-scraper/translate-image.ts:79
Uploads a file to Aliyun OSS using the provided credentials.
Parameters
localPath
string
The full path to the local image file.
credentials
The credentials object received from getUploadCredentials().
Returns
Promise<string>
A promise that resolves to the public URL of the uploaded image.
Throws
Throws an error if the upload fails.
Example
const url = await client.uploadToAliyunOSS('./product.jpg', creds);translateEcommerce()
translateEcommerce(
imageUrl,sourceLanguage,targetLanguage):Promise<any>
Defined in: src/_other-scraper/translate-image.ts:117
Submits an uploaded image URL for translation in an e-commerce context and returns the translated text along with additional metadata.
Parameters
imageUrl
string
The public URL of the uploaded image.
sourceLanguage
string (default: 'auto')
The language code of the original text.
targetLanguage
string (default: 'en')
The desired output language.
Returns
Promise<any>
A promise that resolves to the translation result object.
Example
const result = await client.translateEcommerce(url, 'ja', 'en');translateImage()
translateImage(
buffer,filename,from,to):Promise<any>
Defined in: src/_other-scraper/translate-image.ts:152
Submits a general image buffer for standard OCR translation.
Parameters
buffer
Buffer
The raw image buffer.
filename
string
The filename associated with the image.
from
string (default: 'auto')
The source language.
to
string (default: 'en')
The target language.
Returns
Promise<any>
A promise that resolves to the translation response data.
Example
const data = await client.translateImage(fs.readFileSync('ocr.jpg'), 'ocr.jpg');translateManga()
translateManga(
buffer,filename,from,to):Promise<any>
Defined in: src/_other-scraper/translate-image.ts:188
Submits an image for manga-specific translation, supporting automatic panel detection and direction awareness.
Parameters
buffer
Buffer
The image buffer.
filename
string
The name of the manga image file.
from
string (default: 'auto')
The source language.
to
string (default: 'ENG')
The target language.
Returns
Promise<any>
A promise that resolves to the translation data, including text regions and annotations.
Example
const result = await client.translateManga(fs.readFileSync('manga.jpg'), 'manga.jpg');uploadFile()
uploadFile(
localFilePath):Promise<string>
Defined in: src/_other-scraper/translate-image.ts:223
A helper method to upload a file and return the final image URL. This method internally handles credential fetching and OSS upload.
Parameters
localFilePath
string
The full path to the local image file.
Returns
Promise<string>
A promise that resolves to the final image URL.
Example
const url = await client.uploadFile('./poster.jpg');