Chg: 文字数制限回避を1行ずつに

This commit is contained in:
2026-05-03 14:01:45 +09:00
parent d429503b78
commit 2b21401587
+28 -14
View File
@@ -18,21 +18,38 @@ export const createUeuse = async (data: ApiMap["ueuse/create"]["body"], title: s
const maxLength = mem.max_length;
const excessedMessage = "👉返信に続きがあります。";
let remainingText = data.text;
// 行単位で分割
let lines = data.text.split(EOL);
let firstUniqid = "";
while (remainingText.length > 0) {
while (lines.length > 0) {
let currentText = "";
let bodyTextLength = 0;
if (remainingText.length <= maxLength) {
currentText = remainingText;
bodyTextLength = remainingText.length;
remainingText = "";
const limit = maxLength - (excessedMessage.length + EOL.length * 2);
while (lines.length > 0) {
const nextLine = lines[0];
if (nextLine === undefined) break;
if (nextLine.length > limit && currentText === "") {
const targetLine = lines.shift() || "";
currentText = targetLine.slice(0, limit);
lines.unshift(targetLine.slice(limit));
break;
}
const potentialText = currentText ? currentText + EOL + nextLine : nextLine;
if (potentialText.length <= limit) {
currentText = potentialText;
lines.shift();
} else {
bodyTextLength = maxLength - excessedMessage.length - 2;
currentText = remainingText.slice(0, bodyTextLength) + EOL.repeat(2) + excessedMessage;
remainingText = remainingText.slice(bodyTextLength);
break;
}
}
if (lines.length > 0) {
currentText += EOL.repeat(2) + excessedMessage;
}
let postedUniqid = "";
@@ -64,10 +81,7 @@ export const createUeuse = async (data: ApiMap["ueuse/create"]["body"], title: s
break;
}
if (firstUniqid === "") {
firstUniqid = postedUniqid;
}
if (firstUniqid === "") firstUniqid = postedUniqid;
console.log(`${title}を投稿:`, postedUniqid);
}
}