このコミットが含まれているのは:
@@ -9,6 +9,7 @@ import type {
|
||||
} from '@/lib/postImportTypes'
|
||||
|
||||
type QueryRowState = {
|
||||
source_row: number
|
||||
title: string
|
||||
thumbnail_base: string
|
||||
original_created_from: string
|
||||
@@ -34,6 +35,7 @@ type EncodedSkip = 'e' | 'm'
|
||||
type EncodedImportStatus = 'p' | 'c' | 's' | 'f'
|
||||
|
||||
type EncodedRowState = {
|
||||
n?: number
|
||||
u?: string
|
||||
t?: string
|
||||
h?: string
|
||||
@@ -241,6 +243,7 @@ const manualFields = (row: PostImportRow): string[] =>
|
||||
|
||||
|
||||
const baseRowState = (row: PostImportRow): QueryRowState => ({
|
||||
source_row: row.sourceRow,
|
||||
title: String (row.attributes.title ?? ''),
|
||||
thumbnail_base: String (row.attributes.thumbnailBase ?? ''),
|
||||
original_created_from: String (row.attributes.originalCreatedFrom ?? ''),
|
||||
@@ -257,10 +260,7 @@ const baseRowState = (row: PostImportRow): QueryRowState => ({
|
||||
recoverable: row.recoverable ?? null })
|
||||
|
||||
|
||||
const buildRow = (
|
||||
sourceRow: number,
|
||||
state: FullRowState,
|
||||
): PostImportRow => {
|
||||
const buildRow = (state: FullRowState): PostImportRow => {
|
||||
const manual = new Set (state.manual)
|
||||
const provenance: Record<string, PostImportOrigin> = {
|
||||
url: 'manual',
|
||||
@@ -286,7 +286,7 @@ const buildRow = (
|
||||
parentPostIds: state.parent_post_ids }
|
||||
|
||||
return {
|
||||
sourceRow,
|
||||
sourceRow: state.source_row,
|
||||
url: state.url,
|
||||
attributes,
|
||||
fieldWarnings: { },
|
||||
@@ -336,6 +336,7 @@ const parseEncodedRow = (
|
||||
const existingPostId = row['e']
|
||||
const createdPostId = row['c']
|
||||
const recoverable = row['r']
|
||||
const sourceRow = row['n']
|
||||
|
||||
if (requireUrl && typeof url !== 'string')
|
||||
return null
|
||||
@@ -357,6 +358,11 @@ const parseEncodedRow = (
|
||||
return null
|
||||
if (recoverable != null && typeof recoverable !== 'boolean')
|
||||
return null
|
||||
if (sourceRow != null
|
||||
&& !(typeof sourceRow === 'number'
|
||||
&& Number.isInteger (sourceRow)
|
||||
&& sourceRow > 0))
|
||||
return null
|
||||
|
||||
const stringFields = [
|
||||
['t', 'title'],
|
||||
@@ -385,6 +391,10 @@ const parseEncodedRow = (
|
||||
}
|
||||
|
||||
return {
|
||||
source_row:
|
||||
typeof sourceRow === 'number'
|
||||
? sourceRow
|
||||
: 1,
|
||||
url: typeof url === 'string' ? url : '',
|
||||
title: parsedStrings.title,
|
||||
thumbnail_base: parsedStrings.thumbnail_base,
|
||||
@@ -412,7 +422,8 @@ const parseSingleRow = (params: URLSearchParams): ParsedPostNewState | null => {
|
||||
key => key === 'url' || key === 'session_id')
|
||||
if (hasOnlyUrl)
|
||||
{
|
||||
const row = buildRow (1, {
|
||||
const row = buildRow ({
|
||||
source_row: 1,
|
||||
url,
|
||||
title: '',
|
||||
thumbnail_base: '',
|
||||
@@ -449,7 +460,8 @@ const parseSingleRow = (params: URLSearchParams): ParsedPostNewState | null => {
|
||||
if (importStatus != null && !(isValidImportStatus (importStatus)))
|
||||
return null
|
||||
|
||||
const row = buildRow (1, {
|
||||
const row = buildRow ({
|
||||
source_row: 1,
|
||||
url,
|
||||
title: params.get ('title') ?? '',
|
||||
thumbnail_base: params.get ('thumbnail_base') ?? '',
|
||||
@@ -508,7 +520,7 @@ const parseMetaRows = (
|
||||
if (fullRows.some (row => row == null))
|
||||
return null
|
||||
|
||||
const rows = fullRows.map ((row, index) => buildRow (index + 1, row as FullRowState))
|
||||
const rows = fullRows.map (row => buildRow (row as FullRowState))
|
||||
return {
|
||||
rows,
|
||||
source: urls.join ('\n'),
|
||||
@@ -539,7 +551,7 @@ const parseFullState = async (stateValue: string): Promise<ParsedPostNewState |
|
||||
if (fullRows.some (row => row == null))
|
||||
return null
|
||||
|
||||
const rows = fullRows.map ((row, index) => buildRow (index + 1, row as FullRowState))
|
||||
const rows = fullRows.map (row => buildRow (row as FullRowState))
|
||||
return {
|
||||
rows,
|
||||
source: rows.map (row => row.url).join ('\n'),
|
||||
@@ -594,6 +606,7 @@ const encodeRowState = (
|
||||
const base = baseRowState (row)
|
||||
const encoded: EncodedRowState = includeUrl ? { u: row.url } : { }
|
||||
|
||||
encoded.n = base.source_row
|
||||
if (base.title !== '')
|
||||
encoded.t = base.title
|
||||
if (base.thumbnail_base !== '')
|
||||
@@ -684,19 +697,19 @@ const serialiseCompressedRows = async (
|
||||
rows: PostImportRow[],
|
||||
): Promise<SerialisedPostNewState | null> => {
|
||||
try
|
||||
{
|
||||
for (let count = rows.length; count > 0; --count)
|
||||
{
|
||||
const nextRows = rows.slice (0, count)
|
||||
const encoded = encodeStateRows (nextRows)
|
||||
const state = await encodeCompressedState (JSON.stringify (encoded))
|
||||
const payload = state.slice (COMPRESSED_STATE_PREFIX.length)
|
||||
if (payload.length <= MAX_COMPRESSED_STATE_LENGTH)
|
||||
return {
|
||||
path: `/posts/new?state=${ state }`,
|
||||
complete: count === rows.length }
|
||||
}
|
||||
}
|
||||
{
|
||||
for (let count = rows.length; count > 0; --count)
|
||||
{
|
||||
const nextRows = rows.slice (0, count)
|
||||
const encoded = encodeStateRows (nextRows)
|
||||
const state = await encodeCompressedState (JSON.stringify (encoded))
|
||||
const path = `/posts/new?state=${ state }`
|
||||
if (path.length <= MAX_COMPRESSED_STATE_LENGTH)
|
||||
return {
|
||||
path,
|
||||
complete: count === rows.length }
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
新しい課題から参照
ユーザをブロックする