feat: converter de maiúsculas para primeira maiúscula
This commit is contained in:
parent
97c2d32e03
commit
e027026c75
@ -6,10 +6,12 @@ using OnlyOneAccessTemplate.Models;
|
|||||||
|
|
||||||
namespace OnlyOneAccessTemplate.Controllers
|
namespace OnlyOneAccessTemplate.Controllers
|
||||||
{
|
{
|
||||||
|
[ApiController]
|
||||||
|
[Route("converter")] // Adicione esta linha
|
||||||
public class ConverterController : BaseController
|
public class ConverterController : BaseController
|
||||||
{
|
{
|
||||||
private readonly IServiceProvider _serviceProvider;
|
private readonly IServiceProvider _serviceProvider;
|
||||||
private readonly ILogger _logger;
|
//private readonly ILogger _logger;
|
||||||
private readonly Dictionary<string, Type> _converterTypes;
|
private readonly Dictionary<string, Type> _converterTypes;
|
||||||
|
|
||||||
public ConverterController(
|
public ConverterController(
|
||||||
@ -18,20 +20,21 @@ namespace OnlyOneAccessTemplate.Controllers
|
|||||||
ISeoService seoService,
|
ISeoService seoService,
|
||||||
IMemoryCache cache,
|
IMemoryCache cache,
|
||||||
IConfiguration configuration,
|
IConfiguration configuration,
|
||||||
IServiceProvider serviceProvider,
|
IServiceProvider serviceProvider
|
||||||
ILogger logger
|
//,ILogger logger
|
||||||
)
|
)
|
||||||
: base(siteConfig, languageService, seoService, cache, configuration)
|
: base(siteConfig, languageService, seoService, cache, configuration)
|
||||||
{
|
{
|
||||||
_serviceProvider = serviceProvider;
|
_serviceProvider = serviceProvider;
|
||||||
this._logger = logger;
|
//this._logger = logger;
|
||||||
|
|
||||||
// Registrar tipos de conversores disponíveis
|
// Registrar tipos de conversores disponíveis
|
||||||
_converterTypes = new Dictionary<string, Type>
|
_converterTypes = new Dictionary<string, Type>
|
||||||
{
|
{
|
||||||
["text-case"] = typeof(TextCaseConverterService),
|
["text-case"] = typeof(TextCaseConverterService),
|
||||||
["csv-json"] = typeof(CsvToJsonConverterService),
|
["csv-json"] = typeof(CsvToJsonConverterService),
|
||||||
["image-ocr"] = typeof(ImageToTextConverterService)
|
["image-ocr"] = typeof(ImageToTextConverterService),
|
||||||
|
["sentence-converter"] = typeof(UpperLowerConversorService)
|
||||||
// Adicionar novos conversores aqui
|
// Adicionar novos conversores aqui
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -98,7 +101,7 @@ namespace OnlyOneAccessTemplate.Controllers
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Erro na conversão {ConverterType}", converterType);
|
//_logger.LogError(ex, "Erro na conversão {ConverterType}", converterType);
|
||||||
return StatusCode(500, new { success = false, message = "Erro interno do servidor" });
|
return StatusCode(500, new { success = false, message = "Erro interno do servidor" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -121,9 +124,15 @@ namespace OnlyOneAccessTemplate.Controllers
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Erro ao buscar configuração do conversor {ConverterType}", converterType);
|
//_logger.LogError(ex, "Erro ao buscar configuração do conversor {ConverterType}", converterType);
|
||||||
return StatusCode(500, new { success = false, message = "Erro interno do servidor" });
|
return StatusCode(500, new { success = false, message = "Erro interno do servidor" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("test")]
|
||||||
|
public IActionResult Test()
|
||||||
|
{
|
||||||
|
return Ok(new { message = "Controller funcionando", timestamp = DateTime.Now });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,6 +40,7 @@ builder.Services.AddScoped<TextCaseConverterService>();
|
|||||||
builder.Services.AddScoped<CsvToJsonConverterService>();
|
builder.Services.AddScoped<CsvToJsonConverterService>();
|
||||||
builder.Services.AddScoped<ImageToTextConverterService>();
|
builder.Services.AddScoped<ImageToTextConverterService>();
|
||||||
|
|
||||||
|
builder.Services.AddScoped<UpperLowerConversorService>();
|
||||||
// Adicione aqui novos conversores conforme necessário:
|
// Adicione aqui novos conversores conforme necessário:
|
||||||
// builder.Services.AddScoped<SeuNovoConverterService>();
|
// builder.Services.AddScoped<SeuNovoConverterService>();
|
||||||
|
|
||||||
@ -59,8 +60,7 @@ builder.Services.AddResponseCaching();
|
|||||||
// Memory Cache
|
// Memory Cache
|
||||||
builder.Services.AddMemoryCache();
|
builder.Services.AddMemoryCache();
|
||||||
|
|
||||||
// Logging
|
// Loggingbuilder.Logging.ClearProviders();
|
||||||
builder.Logging.ClearProviders();
|
|
||||||
builder.Logging.AddConsole();
|
builder.Logging.AddConsole();
|
||||||
builder.Logging.AddDebug();
|
builder.Logging.AddDebug();
|
||||||
|
|
||||||
|
|||||||
85
OnlyOneAccessTemplate/Services/UpperLowerConversorService.cs
Normal file
85
OnlyOneAccessTemplate/Services/UpperLowerConversorService.cs
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
using OnlyOneAccessTemplate.Services.OnlyOneAccessTemplate.Services;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OnlyOneAccessTemplate.Services
|
||||||
|
{
|
||||||
|
public class UpperLowerConversorService : BaseConverterService
|
||||||
|
{
|
||||||
|
public override string ConverterType => "text-case-sentence";
|
||||||
|
|
||||||
|
public override string ConverterName => "Maiúsculas para minúsculas";
|
||||||
|
|
||||||
|
public UpperLowerConversorService(ILogger<UpperLowerConversorService> logger, IConfiguration configuration)
|
||||||
|
: base(logger, configuration) { }
|
||||||
|
|
||||||
|
public override async Task<ConversionResult> ConvertAsync(ConversionRequest request)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Sua lógica de conversão aqui
|
||||||
|
var resultado = ConvertToSentenceCase(request.TextInput);
|
||||||
|
|
||||||
|
return new ConversionResult(true, OutputText: resultado);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Erro na conversão");
|
||||||
|
return new ConversionResult(false, ErrorMessage: "Erro ao processar");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string ConvertToSentenceCase(string text)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(text))
|
||||||
|
return text;
|
||||||
|
|
||||||
|
// Converte todo o texto para minúsculas primeiro
|
||||||
|
string lowerText = text.ToLower();
|
||||||
|
|
||||||
|
// StringBuilder para construir o resultado
|
||||||
|
StringBuilder result = new StringBuilder(lowerText);
|
||||||
|
|
||||||
|
// Capitaliza a primeira letra do texto se for uma letra
|
||||||
|
if (result.Length > 0 && char.IsLetter(result[0]))
|
||||||
|
{
|
||||||
|
result[0] = char.ToUpper(result[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Regex para encontrar início de frases/parágrafos
|
||||||
|
// Procura por pontos, exclamações, interrogações ou quebras de linha
|
||||||
|
// seguidos por espaços e uma letra
|
||||||
|
string pattern = @"([.!?\n]\s*)([a-z])";
|
||||||
|
|
||||||
|
string resultText = result.ToString();
|
||||||
|
resultText = Regex.Replace(resultText, pattern, match =>
|
||||||
|
{
|
||||||
|
return match.Groups[1].Value + char.ToUpper(match.Groups[2].Value[0]);
|
||||||
|
});
|
||||||
|
|
||||||
|
return resultText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override ConverterConfiguration GetConfiguration(string language)
|
||||||
|
{
|
||||||
|
var texts = GetLocalizedTexts(language);
|
||||||
|
|
||||||
|
// Personalize os textos para seu conversor
|
||||||
|
texts["ConverterTitle"] = language switch
|
||||||
|
{
|
||||||
|
"en" => "Sentence Case Convert",
|
||||||
|
"es" => "TÍTULO DE TU CONVERTIDOR",
|
||||||
|
_ => "Converter para primeira maiúscula"
|
||||||
|
};
|
||||||
|
|
||||||
|
return new ConverterConfiguration
|
||||||
|
{
|
||||||
|
ConverterType = "text", // ou "file" ou "url"
|
||||||
|
OutputType = "text", // ou "download" ou "preview"
|
||||||
|
HasAdvancedOptions = false,
|
||||||
|
AllowShare = true,
|
||||||
|
LocalizedTexts = texts
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -151,6 +151,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
<script src="~/js/converters/sentence-converter.js?v=1.0"></script>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- JavaScript Base do Conversor -->
|
<!-- JavaScript Base do Conversor -->
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
// Exemplo 1: Conversor de Maiúsculas/Minúsculas
|
// Exemplo 1: Conversor de Maiúsculas/Minúsculas
|
||||||
"Converter": {
|
"Converter": {
|
||||||
"Type": "text-case",
|
"Type": "text-case-sentence",
|
||||||
"Name": "Conversor de Maiúsculas e Minúsculas"
|
"Name": "Conversor de Maiúsculas e Minúsculas"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,165 @@
|
|||||||
|
// wwwroot/js/converters/image-ocr-converter.js
|
||||||
|
// Implementação específica para conversor de imagem para texto (OCR)
|
||||||
|
|
||||||
|
async function performConversion(formData) {
|
||||||
|
const fileInput = formData.get('file');
|
||||||
|
|
||||||
|
if (!fileInput || fileInput.size === 0) {
|
||||||
|
throw new Error('Por favor, selecione uma imagem');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validar tipo de arquivo
|
||||||
|
const allowedTypes = ['image/jpeg', 'image/jpg', 'image/png', 'image/gif', 'image/bmp', 'application/pdf'];
|
||||||
|
if (!allowedTypes.includes(fileInput.type)) {
|
||||||
|
throw new Error('Formato de arquivo não suportado. Use JPG, PNG, GIF, BMP ou PDF.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validar tamanho (15MB)
|
||||||
|
if (fileInput.size > 15 * 1024 * 1024) {
|
||||||
|
throw new Error('Arquivo muito grande. Tamanho máximo: 15MB');
|
||||||
|
}
|
||||||
|
|
||||||
|
const requestData = new FormData();
|
||||||
|
requestData.append('inputType', 'file');
|
||||||
|
requestData.append('fileInput', fileInput);
|
||||||
|
requestData.append('language', document.documentElement.lang || 'pt');
|
||||||
|
|
||||||
|
// Adicionar opções de OCR se houver
|
||||||
|
const ocrLanguage = formData.get('ocrLanguage') || 'por';
|
||||||
|
const options = { ocrLanguage: ocrLanguage };
|
||||||
|
requestData.append('options', JSON.stringify(options));
|
||||||
|
|
||||||
|
const response = await fetch('/converter/api/convert/image-ocr', {
|
||||||
|
method: 'POST',
|
||||||
|
body: requestData
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const error = await response.json();
|
||||||
|
throw new Error(error.message || 'Erro no processamento da imagem');
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
|
||||||
|
// Mostrar resultado do OCR
|
||||||
|
showOcrResult(result.outputText, fileInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
function showOcrResult(extractedText, originalFile) {
|
||||||
|
const outputTextElement = document.getElementById('outputText');
|
||||||
|
const successActions = document.getElementById('successActions');
|
||||||
|
|
||||||
|
if (outputTextElement) {
|
||||||
|
outputTextElement.value = extractedText;
|
||||||
|
document.getElementById('outputArea').style.display = 'block';
|
||||||
|
successActions.style.display = 'block';
|
||||||
|
|
||||||
|
// Mostrar preview da imagem
|
||||||
|
showImagePreview(originalFile);
|
||||||
|
|
||||||
|
// Adicionar botão para salvar texto
|
||||||
|
addSaveTextButton(extractedText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function showImagePreview(file) {
|
||||||
|
const previewContainer = document.getElementById('imagePreview');
|
||||||
|
if (previewContainer && file.type.startsWith('image/')) {
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = function (e) {
|
||||||
|
previewContainer.innerHTML = `
|
||||||
|
<div class="mt-3">
|
||||||
|
<small class="text-muted">Imagem processada:</small><br>
|
||||||
|
<img src="${e.target.result}" alt="Preview" class="img-thumbnail mt-1" style="max-height: 200px;">
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
};
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function addSaveTextButton(text) {
|
||||||
|
const successActions = document.getElementById('successActions');
|
||||||
|
|
||||||
|
if (document.getElementById('saveTextBtn')) return;
|
||||||
|
|
||||||
|
const saveBtn = document.createElement('button');
|
||||||
|
saveBtn.id = 'saveTextBtn';
|
||||||
|
saveBtn.type = 'button';
|
||||||
|
saveBtn.className = 'btn btn-sm btn-outline-success';
|
||||||
|
saveBtn.innerHTML = '<i class="fas fa-save me-1"></i> Salvar Texto';
|
||||||
|
|
||||||
|
saveBtn.addEventListener('click', () => {
|
||||||
|
const blob = new Blob([text], { type: 'text/plain;charset=utf-8' });
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
const a = document.createElement('a');
|
||||||
|
a.href = url;
|
||||||
|
a.download = 'texto-extraido.txt';
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
document.body.removeChild(a);
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
});
|
||||||
|
|
||||||
|
successActions.appendChild(saveBtn);
|
||||||
|
}
|
||||||
|
|
||||||
|
function initializeConverter() {
|
||||||
|
setupAdvancedOcrOptions();
|
||||||
|
setupImagePreview();
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupAdvancedOcrOptions() {
|
||||||
|
const advancedContainer = document.getElementById('advancedSettings');
|
||||||
|
if (advancedContainer) {
|
||||||
|
advancedContainer.innerHTML = `
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<label class="form-label">Idioma do OCR</label>
|
||||||
|
<select name="ocrLanguage" class="form-select">
|
||||||
|
<option value="por">Português</option>
|
||||||
|
<option value="eng">English</option>
|
||||||
|
<option value="spa">Español</option>
|
||||||
|
<option value="fra">Français</option>
|
||||||
|
<option value="deu">Deutsch</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<label class="form-label">Qualidade</label>
|
||||||
|
<select name="quality" class="form-select">
|
||||||
|
<option value="balanced">Balanceada</option>
|
||||||
|
<option value="fast">Rápida</option>
|
||||||
|
<option value="accurate">Precisa</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupImagePreview() {
|
||||||
|
const fileInput = document.getElementById('fileInput');
|
||||||
|
if (fileInput) {
|
||||||
|
fileInput.addEventListener('change', function (e) {
|
||||||
|
const file = e.target.files[0];
|
||||||
|
if (file && file.type.startsWith('image/')) {
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = function (event) {
|
||||||
|
let previewContainer = document.getElementById('imagePreview');
|
||||||
|
if (!previewContainer) {
|
||||||
|
previewContainer = document.createElement('div');
|
||||||
|
previewContainer.id = 'imagePreview';
|
||||||
|
fileInput.parentNode.appendChild(previewContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
previewContainer.innerHTML = `
|
||||||
|
<div class="mt-2">
|
||||||
|
<img src="${event.target.result}" alt="Preview" class="img-thumbnail" style="max-height: 150px;">
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
};
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,45 @@
|
|||||||
|
async function performConversion(formData) {
|
||||||
|
// Validar entrada
|
||||||
|
const input = formData.get('inputText') || formData.get('file');
|
||||||
|
if (!input) {
|
||||||
|
throw new Error('Por favor, forneça uma entrada válida');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Preparar dados
|
||||||
|
const requestData = new FormData();
|
||||||
|
requestData.append('inputType', 'text'); // ou 'file'
|
||||||
|
requestData.append('textInput', input);
|
||||||
|
requestData.append('language', document.documentElement.lang || 'pt');
|
||||||
|
|
||||||
|
// Fazer requisição
|
||||||
|
const response = await fetch('/converter/api/convert/sentence-converter', {
|
||||||
|
method: 'POST',
|
||||||
|
body: requestData
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const error = await response.json();
|
||||||
|
throw new Error(error.message || 'Erro na conversão');
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
|
||||||
|
// Mostrar resultado
|
||||||
|
showResult(result.outputText);
|
||||||
|
}
|
||||||
|
|
||||||
|
function showResult(output) {
|
||||||
|
const outputElement = document.getElementById('outputText');
|
||||||
|
const successActions = document.getElementById('successActions');
|
||||||
|
|
||||||
|
if (outputElement) {
|
||||||
|
outputElement.value = output;
|
||||||
|
document.getElementById('outputArea').style.display = 'block';
|
||||||
|
successActions.style.display = 'block';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function initializeConverter() {
|
||||||
|
// Inicializações específicas do seu conversor
|
||||||
|
console.log('Conversor inicializado');
|
||||||
|
}
|
||||||
@ -246,168 +246,3 @@ function debounce(func, wait) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// wwwroot/js/converters/image-ocr-converter.js
|
|
||||||
// Implementação específica para conversor de imagem para texto (OCR)
|
|
||||||
|
|
||||||
async function performConversion(formData) {
|
|
||||||
const fileInput = formData.get('file');
|
|
||||||
|
|
||||||
if (!fileInput || fileInput.size === 0) {
|
|
||||||
throw new Error('Por favor, selecione uma imagem');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validar tipo de arquivo
|
|
||||||
const allowedTypes = ['image/jpeg', 'image/jpg', 'image/png', 'image/gif', 'image/bmp', 'application/pdf'];
|
|
||||||
if (!allowedTypes.includes(fileInput.type)) {
|
|
||||||
throw new Error('Formato de arquivo não suportado. Use JPG, PNG, GIF, BMP ou PDF.');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validar tamanho (15MB)
|
|
||||||
if (fileInput.size > 15 * 1024 * 1024) {
|
|
||||||
throw new Error('Arquivo muito grande. Tamanho máximo: 15MB');
|
|
||||||
}
|
|
||||||
|
|
||||||
const requestData = new FormData();
|
|
||||||
requestData.append('inputType', 'file');
|
|
||||||
requestData.append('fileInput', fileInput);
|
|
||||||
requestData.append('language', document.documentElement.lang || 'pt');
|
|
||||||
|
|
||||||
// Adicionar opções de OCR se houver
|
|
||||||
const ocrLanguage = formData.get('ocrLanguage') || 'por';
|
|
||||||
const options = { ocrLanguage: ocrLanguage };
|
|
||||||
requestData.append('options', JSON.stringify(options));
|
|
||||||
|
|
||||||
const response = await fetch('/converter/api/convert/image-ocr', {
|
|
||||||
method: 'POST',
|
|
||||||
body: requestData
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
const error = await response.json();
|
|
||||||
throw new Error(error.message || 'Erro no processamento da imagem');
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await response.json();
|
|
||||||
|
|
||||||
// Mostrar resultado do OCR
|
|
||||||
showOcrResult(result.outputText, fileInput);
|
|
||||||
}
|
|
||||||
|
|
||||||
function showOcrResult(extractedText, originalFile) {
|
|
||||||
const outputTextElement = document.getElementById('outputText');
|
|
||||||
const successActions = document.getElementById('successActions');
|
|
||||||
|
|
||||||
if (outputTextElement) {
|
|
||||||
outputTextElement.value = extractedText;
|
|
||||||
document.getElementById('outputArea').style.display = 'block';
|
|
||||||
successActions.style.display = 'block';
|
|
||||||
|
|
||||||
// Mostrar preview da imagem
|
|
||||||
showImagePreview(originalFile);
|
|
||||||
|
|
||||||
// Adicionar botão para salvar texto
|
|
||||||
addSaveTextButton(extractedText);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function showImagePreview(file) {
|
|
||||||
const previewContainer = document.getElementById('imagePreview');
|
|
||||||
if (previewContainer && file.type.startsWith('image/')) {
|
|
||||||
const reader = new FileReader();
|
|
||||||
reader.onload = function (e) {
|
|
||||||
previewContainer.innerHTML = `
|
|
||||||
<div class="mt-3">
|
|
||||||
<small class="text-muted">Imagem processada:</small><br>
|
|
||||||
<img src="${e.target.result}" alt="Preview" class="img-thumbnail mt-1" style="max-height: 200px;">
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
};
|
|
||||||
reader.readAsDataURL(file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function addSaveTextButton(text) {
|
|
||||||
const successActions = document.getElementById('successActions');
|
|
||||||
|
|
||||||
if (document.getElementById('saveTextBtn')) return;
|
|
||||||
|
|
||||||
const saveBtn = document.createElement('button');
|
|
||||||
saveBtn.id = 'saveTextBtn';
|
|
||||||
saveBtn.type = 'button';
|
|
||||||
saveBtn.className = 'btn btn-sm btn-outline-success';
|
|
||||||
saveBtn.innerHTML = '<i class="fas fa-save me-1"></i> Salvar Texto';
|
|
||||||
|
|
||||||
saveBtn.addEventListener('click', () => {
|
|
||||||
const blob = new Blob([text], { type: 'text/plain;charset=utf-8' });
|
|
||||||
const url = URL.createObjectURL(blob);
|
|
||||||
const a = document.createElement('a');
|
|
||||||
a.href = url;
|
|
||||||
a.download = 'texto-extraido.txt';
|
|
||||||
document.body.appendChild(a);
|
|
||||||
a.click();
|
|
||||||
document.body.removeChild(a);
|
|
||||||
URL.revokeObjectURL(url);
|
|
||||||
});
|
|
||||||
|
|
||||||
successActions.appendChild(saveBtn);
|
|
||||||
}
|
|
||||||
|
|
||||||
function initializeConverter() {
|
|
||||||
setupAdvancedOcrOptions();
|
|
||||||
setupImagePreview();
|
|
||||||
}
|
|
||||||
|
|
||||||
function setupAdvancedOcrOptions() {
|
|
||||||
const advancedContainer = document.getElementById('advancedSettings');
|
|
||||||
if (advancedContainer) {
|
|
||||||
advancedContainer.innerHTML = `
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-6">
|
|
||||||
<label class="form-label">Idioma do OCR</label>
|
|
||||||
<select name="ocrLanguage" class="form-select">
|
|
||||||
<option value="por">Português</option>
|
|
||||||
<option value="eng">English</option>
|
|
||||||
<option value="spa">Español</option>
|
|
||||||
<option value="fra">Français</option>
|
|
||||||
<option value="deu">Deutsch</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="col-md-6">
|
|
||||||
<label class="form-label">Qualidade</label>
|
|
||||||
<select name="quality" class="form-select">
|
|
||||||
<option value="balanced">Balanceada</option>
|
|
||||||
<option value="fast">Rápida</option>
|
|
||||||
<option value="accurate">Precisa</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function setupImagePreview() {
|
|
||||||
const fileInput = document.getElementById('fileInput');
|
|
||||||
if (fileInput) {
|
|
||||||
fileInput.addEventListener('change', function (e) {
|
|
||||||
const file = e.target.files[0];
|
|
||||||
if (file && file.type.startsWith('image/')) {
|
|
||||||
const reader = new FileReader();
|
|
||||||
reader.onload = function (event) {
|
|
||||||
let previewContainer = document.getElementById('imagePreview');
|
|
||||||
if (!previewContainer) {
|
|
||||||
previewContainer = document.createElement('div');
|
|
||||||
previewContainer.id = 'imagePreview';
|
|
||||||
fileInput.parentNode.appendChild(previewContainer);
|
|
||||||
}
|
|
||||||
|
|
||||||
previewContainer.innerHTML = `
|
|
||||||
<div class="mt-2">
|
|
||||||
<img src="${event.target.result}" alt="Preview" class="img-thumbnail" style="max-height: 150px;">
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
};
|
|
||||||
reader.readAsDataURL(file);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user