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