feat: accept any text file in share uploader
This commit is contained in:
+5
-10
@@ -3,7 +3,7 @@
|
||||
import Image from "next/image";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useEffect, useMemo, useRef, useState } from "react";
|
||||
import { FileText, ImagePlus, Upload, X } from "lucide-react";
|
||||
import { FileUp, ImagePlus, Upload, X } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
import { createShareAction } from "@/app/actions/share";
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||
@@ -59,12 +59,8 @@ export function ShareUploadClient() {
|
||||
|
||||
async function loadTextFile(file: File) {
|
||||
setError(null);
|
||||
if (!file.name.toLowerCase().endsWith(".txt")) {
|
||||
setError("เลือกไฟล์ .txt เท่านั้น");
|
||||
return;
|
||||
}
|
||||
if (file.size > MAX_SHARE_TEXT_BYTES) {
|
||||
setError("ไฟล์ข้อความต้องมีขนาดไม่เกิน 5 MiB");
|
||||
setError("ไฟล์ต้องมีขนาดไม่เกิน 5 MiB");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@@ -133,7 +129,7 @@ export function ShareUploadClient() {
|
||||
<div className="flex flex-col gap-1">
|
||||
<CardTitle className="font-mono text-base">share://new</CardTitle>
|
||||
<CardDescription>
|
||||
วางข้อความหรือเปิดไฟล์ .txt แล้วรับลิงก์สำหรับส่งต่อ
|
||||
วางข้อความหรือเลือกไฟล์ แล้วรับลิงก์สำหรับส่งต่อ
|
||||
</CardDescription>
|
||||
</div>
|
||||
<div className="font-mono text-xs text-muted-foreground">
|
||||
@@ -186,8 +182,8 @@ export function ShareUploadClient() {
|
||||
size="sm"
|
||||
onClick={() => textFileRef.current?.click()}
|
||||
>
|
||||
<FileText data-icon="inline-start" />
|
||||
เปิดไฟล์ .txt
|
||||
<FileUp data-icon="inline-start" />
|
||||
เลือกไฟล์
|
||||
</Button>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
หรือลากไฟล์มาวางในช่องข้อความ
|
||||
@@ -200,7 +196,6 @@ export function ShareUploadClient() {
|
||||
<Input
|
||||
ref={textFileRef}
|
||||
type="file"
|
||||
accept=".txt,text/plain"
|
||||
className="hidden"
|
||||
onChange={(event) => {
|
||||
const file = event.target.files?.[0];
|
||||
|
||||
Reference in New Issue
Block a user