@becomeopc/trendpublish 4.0.0-beta.2 → 4.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.js +490 -116
- package/package.json +2 -1
package/dist/app.js
CHANGED
|
@@ -28239,7 +28239,7 @@ function compileCharString(e2, t2, n2, r2) {
|
|
|
28239
28239
|
t2.add(k.curveTo, [e3, n3, r3, i3, a3, o3]);
|
|
28240
28240
|
}
|
|
28241
28241
|
let i2 = [], a2 = 0, o2 = 0, s4 = 0, c3 = null;
|
|
28242
|
-
function
|
|
28242
|
+
function parse4(e3) {
|
|
28243
28243
|
let c4 = new DataView(e3.buffer, e3.byteOffset, e3.byteLength), l2 = 0;
|
|
28244
28244
|
for (; l2 < e3.length; ) {
|
|
28245
28245
|
let u2 = false, d2 = e3[l2++], f3, m2, h2, g3, _3, v3, y3, b3, x3;
|
|
@@ -28273,7 +28273,7 @@ function compileCharString(e2, t2, n2, r2) {
|
|
|
28273
28273
|
t3.privateDict?.subrsIndex && (r3 = t3.privateDict.subrsIndex.objects), r3 && (b3 += getSubroutineBias(r3), x3 = r3[b3]);
|
|
28274
28274
|
} else warn$1(`Invalid fd index for glyph index.`);
|
|
28275
28275
|
} else x3 = n2.subrs[b3 + n2.subrsBias];
|
|
28276
|
-
x3 &&
|
|
28276
|
+
x3 && parse4(x3);
|
|
28277
28277
|
break;
|
|
28278
28278
|
case 11:
|
|
28279
28279
|
return;
|
|
@@ -28340,7 +28340,7 @@ function compileCharString(e2, t2, n2, r2) {
|
|
|
28340
28340
|
i2.push(c4.getInt16(l2)), l2 += 2;
|
|
28341
28341
|
break;
|
|
28342
28342
|
case 29:
|
|
28343
|
-
b3 = i2.pop() + n2.gsubrsBias, x3 = n2.gsubrs[b3], x3 &&
|
|
28343
|
+
b3 = i2.pop() + n2.gsubrsBias, x3 = n2.gsubrs[b3], x3 && parse4(x3);
|
|
28344
28344
|
break;
|
|
28345
28345
|
case 30:
|
|
28346
28346
|
for (; i2.length > 0 && (f3 = a2, h2 = o2 + i2.shift(), m2 = f3 + i2.shift(), g3 = h2 + i2.shift(), a2 = m2 + i2.shift(), o2 = g3 + (i2.length === 1 ? i2.shift() : 0), bezierCurveTo(f3, h2, m2, g3, a2, o2), i2.length !== 0); ) f3 = a2 + i2.shift(), h2 = o2, m2 = f3 + i2.shift(), g3 = h2 + i2.shift(), o2 = g3 + i2.shift(), a2 = m2 + (i2.length === 1 ? i2.shift() : 0), bezierCurveTo(f3, h2, m2, g3, a2, o2);
|
|
@@ -28355,7 +28355,7 @@ function compileCharString(e2, t2, n2, r2) {
|
|
|
28355
28355
|
u2 && (i2.length = 0);
|
|
28356
28356
|
}
|
|
28357
28357
|
}
|
|
28358
|
-
|
|
28358
|
+
parse4(e2);
|
|
28359
28359
|
}
|
|
28360
28360
|
function isHexDigit(e2) {
|
|
28361
28361
|
return e2 >= 48 && e2 <= 57 || e2 >= 65 && e2 <= 70 || e2 >= 97 && e2 <= 102;
|
|
@@ -70358,8 +70358,8 @@ var init_background_tasks2 = __esm({
|
|
|
70358
70358
|
init_logger();
|
|
70359
70359
|
init_runtime2();
|
|
70360
70360
|
InProcessBackgroundTasks = class {
|
|
70361
|
-
constructor(
|
|
70362
|
-
this.logger =
|
|
70361
|
+
constructor(logger7 = new Logger("background-tasks")) {
|
|
70362
|
+
this.logger = logger7;
|
|
70363
70363
|
}
|
|
70364
70364
|
active = /* @__PURE__ */ new Map();
|
|
70365
70365
|
start(name, task) {
|
|
@@ -80084,10 +80084,10 @@ var init_session2 = __esm({
|
|
|
80084
80084
|
}
|
|
80085
80085
|
};
|
|
80086
80086
|
PreparedQuery = class extends SQLitePreparedQuery {
|
|
80087
|
-
constructor(stmt, query,
|
|
80087
|
+
constructor(stmt, query, logger7, cache, queryMetadata, cacheConfig, fields, executeMethod, _isResponseInArrayMode, customResultMapper) {
|
|
80088
80088
|
super("sync", executeMethod, query, cache, queryMetadata, cacheConfig);
|
|
80089
80089
|
this.stmt = stmt;
|
|
80090
|
-
this.logger =
|
|
80090
|
+
this.logger = logger7;
|
|
80091
80091
|
this.fields = fields;
|
|
80092
80092
|
this._isResponseInArrayMode = _isResponseInArrayMode;
|
|
80093
80093
|
this.customResultMapper = customResultMapper;
|
|
@@ -80099,10 +80099,10 @@ var init_session2 = __esm({
|
|
|
80099
80099
|
return this.stmt.run(...params);
|
|
80100
80100
|
}
|
|
80101
80101
|
all(placeholderValues) {
|
|
80102
|
-
const { fields, joinsNotNullableMap, query, logger:
|
|
80102
|
+
const { fields, joinsNotNullableMap, query, logger: logger7, stmt, customResultMapper } = this;
|
|
80103
80103
|
if (!fields && !customResultMapper) {
|
|
80104
80104
|
const params = fillPlaceholders(query.params, placeholderValues ?? {});
|
|
80105
|
-
|
|
80105
|
+
logger7.logQuery(query.sql, params);
|
|
80106
80106
|
return stmt.all(...params);
|
|
80107
80107
|
}
|
|
80108
80108
|
const rows = this.values(placeholderValues);
|
|
@@ -80144,11 +80144,11 @@ var init_session2 = __esm({
|
|
|
80144
80144
|
import Client from "better-sqlite3";
|
|
80145
80145
|
function construct(client, config = {}) {
|
|
80146
80146
|
const dialect = new SQLiteSyncDialect({ casing: config.casing });
|
|
80147
|
-
let
|
|
80147
|
+
let logger7;
|
|
80148
80148
|
if (config.logger === true) {
|
|
80149
|
-
|
|
80149
|
+
logger7 = new DefaultLogger();
|
|
80150
80150
|
} else if (config.logger !== false) {
|
|
80151
|
-
|
|
80151
|
+
logger7 = config.logger;
|
|
80152
80152
|
}
|
|
80153
80153
|
let schema;
|
|
80154
80154
|
if (config.schema) {
|
|
@@ -80162,7 +80162,7 @@ function construct(client, config = {}) {
|
|
|
80162
80162
|
tableNamesMap: tablesConfig.tableNamesMap
|
|
80163
80163
|
};
|
|
80164
80164
|
}
|
|
80165
|
-
const session = new BetterSQLiteSession(client, dialect, schema, { logger:
|
|
80165
|
+
const session = new BetterSQLiteSession(client, dialect, schema, { logger: logger7 });
|
|
80166
80166
|
const db = new BetterSQLite3Database("sync", dialect, session, schema);
|
|
80167
80167
|
db.$client = client;
|
|
80168
80168
|
return db;
|
|
@@ -86063,6 +86063,277 @@ var init_image_asset = __esm({
|
|
|
86063
86063
|
}
|
|
86064
86064
|
});
|
|
86065
86065
|
|
|
86066
|
+
// ../server/src/domain/publishing/image-delivery.ts
|
|
86067
|
+
import { parse as parse2 } from "node:path";
|
|
86068
|
+
import sharp from "sharp";
|
|
86069
|
+
async function prepareImageForDelivery(asset, spec, signal) {
|
|
86070
|
+
signal.throwIfAborted();
|
|
86071
|
+
const maxBytes = assertPositiveInt(spec.maxBytes, "maxBytes");
|
|
86072
|
+
const targetBytes = Math.min(
|
|
86073
|
+
assertPositiveInt(spec.targetBytes ?? maxBytes, "targetBytes"),
|
|
86074
|
+
maxBytes
|
|
86075
|
+
);
|
|
86076
|
+
const initialQuality = clampQuality(spec.initialQuality ?? DEFAULT_INITIAL_QUALITY);
|
|
86077
|
+
const minQuality = Math.min(initialQuality, clampQuality(spec.minQuality ?? DEFAULT_MIN_QUALITY));
|
|
86078
|
+
const maxDimension = spec.maxDimension ?? DEFAULT_MAX_DIMENSION;
|
|
86079
|
+
const minDimension = spec.minDimension ?? DEFAULT_MIN_DIMENSION;
|
|
86080
|
+
const image = sharp(asset.bytes, { limitInputPixels: MAX_INPUT_PIXELS });
|
|
86081
|
+
const metadata = await image.metadata();
|
|
86082
|
+
signal.throwIfAborted();
|
|
86083
|
+
if (!metadata.format || !isSupportedFormat(metadata.format)) {
|
|
86084
|
+
throw new Error("\u56FE\u7247\u9884\u5904\u7406\u4EC5\u652F\u6301 JPEG\u3001PNG\u3001WebP \u548C GIF \u683C\u5F0F");
|
|
86085
|
+
}
|
|
86086
|
+
const { width, height } = metadata.autoOrient;
|
|
86087
|
+
if (!(width > 0 && height > 0)) {
|
|
86088
|
+
throw new Error("\u65E0\u6CD5\u89E3\u6790\u56FE\u7247\u6709\u6548\u5C3A\u5BF8");
|
|
86089
|
+
}
|
|
86090
|
+
const baseName = normalizedBaseName(asset.filename);
|
|
86091
|
+
const format = metadata.format;
|
|
86092
|
+
const isAnimated = (metadata.pages ?? 1) > 1;
|
|
86093
|
+
const canPassthroughAnimated = format === "gif" || format === "webp";
|
|
86094
|
+
if (spec.allowedFormats.includes(format) && (!isAnimated || canPassthroughAnimated) && asset.bytes.byteLength <= targetBytes) {
|
|
86095
|
+
await image.stats();
|
|
86096
|
+
signal.throwIfAborted();
|
|
86097
|
+
return {
|
|
86098
|
+
asset: buildLoadedAsset(asset.bytes, baseName, format),
|
|
86099
|
+
transformed: false,
|
|
86100
|
+
originalBytes: asset.bytes.byteLength,
|
|
86101
|
+
uploadBytes: asset.bytes.byteLength,
|
|
86102
|
+
width,
|
|
86103
|
+
height,
|
|
86104
|
+
format
|
|
86105
|
+
};
|
|
86106
|
+
}
|
|
86107
|
+
let preserveAlpha = false;
|
|
86108
|
+
if (spec.allowTransparency && metadata.hasAlpha) {
|
|
86109
|
+
const stats = await image.stats();
|
|
86110
|
+
signal.throwIfAborted();
|
|
86111
|
+
preserveAlpha = !stats.isOpaque;
|
|
86112
|
+
}
|
|
86113
|
+
const primaryFormat = pickTargetFormat(spec.allowedFormats, preserveAlpha);
|
|
86114
|
+
const raw2 = await decodeNormalizedRaw(asset.bytes, width, height, maxDimension, signal);
|
|
86115
|
+
const rawLongestEdge = Math.max(raw2.width, raw2.height);
|
|
86116
|
+
const effectiveMinDimension = Math.min(rawLongestEdge, Math.max(1, minDimension));
|
|
86117
|
+
const primary = await searchBestEncoding({
|
|
86118
|
+
raw: raw2,
|
|
86119
|
+
format: primaryFormat,
|
|
86120
|
+
targetBytes,
|
|
86121
|
+
initialQuality,
|
|
86122
|
+
minQuality,
|
|
86123
|
+
minDimension: effectiveMinDimension,
|
|
86124
|
+
signal
|
|
86125
|
+
});
|
|
86126
|
+
if (primary.matched) {
|
|
86127
|
+
return toPreparedResult(primary.matched, baseName, primaryFormat, asset.bytes.byteLength);
|
|
86128
|
+
}
|
|
86129
|
+
if (primary.smallest && primary.smallest.bytes.byteLength <= maxBytes) {
|
|
86130
|
+
return toPreparedResult(primary.smallest, baseName, primaryFormat, asset.bytes.byteLength);
|
|
86131
|
+
}
|
|
86132
|
+
if (primaryFormat === "png" && spec.allowedFormats.includes("jpeg")) {
|
|
86133
|
+
const fallback = await searchBestEncoding({
|
|
86134
|
+
raw: raw2,
|
|
86135
|
+
format: "jpeg",
|
|
86136
|
+
targetBytes,
|
|
86137
|
+
initialQuality,
|
|
86138
|
+
minQuality,
|
|
86139
|
+
minDimension: effectiveMinDimension,
|
|
86140
|
+
signal
|
|
86141
|
+
});
|
|
86142
|
+
const chosen = fallback.matched ?? (fallback.smallest && fallback.smallest.bytes.byteLength <= maxBytes ? fallback.smallest : void 0);
|
|
86143
|
+
if (chosen) {
|
|
86144
|
+
return toPreparedResult(chosen, baseName, "jpeg", asset.bytes.byteLength);
|
|
86145
|
+
}
|
|
86146
|
+
}
|
|
86147
|
+
throw new Error(
|
|
86148
|
+
`\u56FE\u7247\u538B\u7F29\u5230\u6700\u5C0F\u8FB9\u957F ${effectiveMinDimension}px \u540E\u4ECD\u8D85\u8FC7\u4E0A\u9650\uFF08\u539F\u56FE ${width}x${height}\uFF0C${asset.bytes.byteLength} \u5B57\u8282\uFF0C\u76EE\u6807 ${targetBytes} \u5B57\u8282\uFF0C\u4E0A\u9650 ${maxBytes} \u5B57\u8282\uFF09`
|
|
86149
|
+
);
|
|
86150
|
+
}
|
|
86151
|
+
async function decodeNormalizedRaw(bytes, width, height, maxDimension, signal) {
|
|
86152
|
+
let pipeline = sharp(bytes, { limitInputPixels: MAX_INPUT_PIXELS }).autoOrient();
|
|
86153
|
+
const longestEdge = Math.max(width, height);
|
|
86154
|
+
if (maxDimension > 0 && longestEdge > maxDimension) {
|
|
86155
|
+
pipeline = pipeline.resize({
|
|
86156
|
+
width: maxDimension,
|
|
86157
|
+
height: maxDimension,
|
|
86158
|
+
fit: "inside",
|
|
86159
|
+
withoutEnlargement: true
|
|
86160
|
+
});
|
|
86161
|
+
}
|
|
86162
|
+
const { data, info: info2 } = await pipeline.raw().toBuffer({ resolveWithObject: true });
|
|
86163
|
+
signal.throwIfAborted();
|
|
86164
|
+
return {
|
|
86165
|
+
data,
|
|
86166
|
+
width: info2.width,
|
|
86167
|
+
height: info2.height,
|
|
86168
|
+
channels: info2.channels
|
|
86169
|
+
};
|
|
86170
|
+
}
|
|
86171
|
+
async function searchBestEncoding(input) {
|
|
86172
|
+
const rawLongestEdge = Math.max(input.raw.width, input.raw.height);
|
|
86173
|
+
let edge = rawLongestEdge;
|
|
86174
|
+
let smallest;
|
|
86175
|
+
while (true) {
|
|
86176
|
+
const high = await encodeRawCandidate(
|
|
86177
|
+
input.raw,
|
|
86178
|
+
edge,
|
|
86179
|
+
input.initialQuality,
|
|
86180
|
+
input.format,
|
|
86181
|
+
input.signal
|
|
86182
|
+
);
|
|
86183
|
+
smallest = pickSmaller(smallest, high);
|
|
86184
|
+
if (high.bytes.byteLength <= input.targetBytes) {
|
|
86185
|
+
return { matched: high, smallest };
|
|
86186
|
+
}
|
|
86187
|
+
let floorCandidate = high;
|
|
86188
|
+
if (input.minQuality < input.initialQuality) {
|
|
86189
|
+
const low = await encodeRawCandidate(
|
|
86190
|
+
input.raw,
|
|
86191
|
+
edge,
|
|
86192
|
+
input.minQuality,
|
|
86193
|
+
input.format,
|
|
86194
|
+
input.signal
|
|
86195
|
+
);
|
|
86196
|
+
smallest = pickSmaller(smallest, low);
|
|
86197
|
+
if (low.bytes.byteLength <= input.targetBytes) {
|
|
86198
|
+
let best = low;
|
|
86199
|
+
let lo2 = input.minQuality;
|
|
86200
|
+
let hi2 = input.initialQuality - 1;
|
|
86201
|
+
while (hi2 - lo2 > 3) {
|
|
86202
|
+
const mid = Math.ceil((lo2 + hi2) / 2);
|
|
86203
|
+
const candidate = await encodeRawCandidate(
|
|
86204
|
+
input.raw,
|
|
86205
|
+
edge,
|
|
86206
|
+
mid,
|
|
86207
|
+
input.format,
|
|
86208
|
+
input.signal
|
|
86209
|
+
);
|
|
86210
|
+
if (candidate.bytes.byteLength <= input.targetBytes) {
|
|
86211
|
+
best = candidate;
|
|
86212
|
+
lo2 = mid;
|
|
86213
|
+
} else {
|
|
86214
|
+
hi2 = mid - 1;
|
|
86215
|
+
}
|
|
86216
|
+
}
|
|
86217
|
+
return { matched: best, smallest };
|
|
86218
|
+
}
|
|
86219
|
+
floorCandidate = low;
|
|
86220
|
+
}
|
|
86221
|
+
if (edge <= input.minDimension) {
|
|
86222
|
+
return { smallest };
|
|
86223
|
+
}
|
|
86224
|
+
const estimatedRatio = Math.sqrt(input.targetBytes / floorCandidate.bytes.byteLength) * 0.92;
|
|
86225
|
+
const scale = Math.min(0.85, Math.max(0.35, estimatedRatio));
|
|
86226
|
+
const nextEdge = Math.max(input.minDimension, Math.floor(edge * scale));
|
|
86227
|
+
edge = nextEdge < edge ? nextEdge : edge - 1;
|
|
86228
|
+
}
|
|
86229
|
+
}
|
|
86230
|
+
async function encodeRawCandidate(raw2, longestEdge, quality, format, signal) {
|
|
86231
|
+
signal.throwIfAborted();
|
|
86232
|
+
const rawLongestEdge = Math.max(raw2.width, raw2.height);
|
|
86233
|
+
let pipeline = sharp(raw2.data, {
|
|
86234
|
+
raw: {
|
|
86235
|
+
width: raw2.width,
|
|
86236
|
+
height: raw2.height,
|
|
86237
|
+
channels: raw2.channels
|
|
86238
|
+
}
|
|
86239
|
+
});
|
|
86240
|
+
if (longestEdge < rawLongestEdge) {
|
|
86241
|
+
pipeline = pipeline.resize({
|
|
86242
|
+
width: longestEdge,
|
|
86243
|
+
height: longestEdge,
|
|
86244
|
+
fit: "inside",
|
|
86245
|
+
withoutEnlargement: true
|
|
86246
|
+
});
|
|
86247
|
+
}
|
|
86248
|
+
if (format === "jpeg" && (raw2.channels === 4 || raw2.channels === 2)) {
|
|
86249
|
+
pipeline = pipeline.flatten({ background: "#ffffff" });
|
|
86250
|
+
}
|
|
86251
|
+
const encoded = format === "png" ? pipeline.png({ palette: true, quality, compressionLevel: 9 }) : format === "webp" ? pipeline.webp({ quality }) : pipeline.jpeg({ quality, mozjpeg: true });
|
|
86252
|
+
const { data, info: info2 } = await encoded.toBuffer({ resolveWithObject: true });
|
|
86253
|
+
signal.throwIfAborted();
|
|
86254
|
+
return {
|
|
86255
|
+
bytes: new Uint8Array(data.buffer, data.byteOffset, data.byteLength),
|
|
86256
|
+
width: info2.width,
|
|
86257
|
+
height: info2.height
|
|
86258
|
+
};
|
|
86259
|
+
}
|
|
86260
|
+
function pickTargetFormat(allowedFormats, preserveAlpha) {
|
|
86261
|
+
if (preserveAlpha) {
|
|
86262
|
+
if (allowedFormats.includes("png")) return "png";
|
|
86263
|
+
if (allowedFormats.includes("webp")) return "webp";
|
|
86264
|
+
if (allowedFormats.includes("jpeg")) return "jpeg";
|
|
86265
|
+
} else {
|
|
86266
|
+
if (allowedFormats.includes("jpeg")) return "jpeg";
|
|
86267
|
+
if (allowedFormats.includes("webp")) return "webp";
|
|
86268
|
+
if (allowedFormats.includes("png")) return "png";
|
|
86269
|
+
}
|
|
86270
|
+
throw new Error("\u76EE\u6807\u6E20\u9053\u672A\u914D\u7F6E\u652F\u6301\u7684\u56FE\u7247\u7F16\u7801\u683C\u5F0F\uFF08\u9700\u8981 jpeg\u3001png \u6216 webp\uFF09");
|
|
86271
|
+
}
|
|
86272
|
+
function toPreparedResult(candidate, baseName, format, originalBytes) {
|
|
86273
|
+
return {
|
|
86274
|
+
asset: buildLoadedAsset(candidate.bytes, baseName, format),
|
|
86275
|
+
transformed: true,
|
|
86276
|
+
originalBytes,
|
|
86277
|
+
uploadBytes: candidate.bytes.byteLength,
|
|
86278
|
+
width: candidate.width,
|
|
86279
|
+
height: candidate.height,
|
|
86280
|
+
format
|
|
86281
|
+
};
|
|
86282
|
+
}
|
|
86283
|
+
function buildLoadedAsset(bytes, baseName, format) {
|
|
86284
|
+
const extension = format === "jpeg" ? "jpg" : format;
|
|
86285
|
+
return {
|
|
86286
|
+
bytes,
|
|
86287
|
+
mimeType: `image/${format}`,
|
|
86288
|
+
filename: `${baseName}.${extension}`
|
|
86289
|
+
};
|
|
86290
|
+
}
|
|
86291
|
+
function normalizedBaseName(filename) {
|
|
86292
|
+
const trimmed = filename.trim();
|
|
86293
|
+
if (!trimmed) return "image";
|
|
86294
|
+
const parsed = parse2(trimmed);
|
|
86295
|
+
if (!parsed.ext && /^\.[a-z0-9]+$/i.test(parsed.base)) {
|
|
86296
|
+
return "image";
|
|
86297
|
+
}
|
|
86298
|
+
const cleaned = parsed.name.replace(/^\.+/, "").trim();
|
|
86299
|
+
return cleaned || "image";
|
|
86300
|
+
}
|
|
86301
|
+
function pickSmaller(current, candidate) {
|
|
86302
|
+
if (!current || candidate.bytes.byteLength < current.bytes.byteLength) return candidate;
|
|
86303
|
+
return current;
|
|
86304
|
+
}
|
|
86305
|
+
function isSupportedFormat(value) {
|
|
86306
|
+
return INPUT_FORMATS.has(value);
|
|
86307
|
+
}
|
|
86308
|
+
function assertPositiveInt(value, name) {
|
|
86309
|
+
if (!Number.isInteger(value) || value < 1) {
|
|
86310
|
+
throw new Error(`\u56FE\u7247\u89C4\u683C ${name} \u5FC5\u987B\u4E3A\u6B63\u6574\u6570`);
|
|
86311
|
+
}
|
|
86312
|
+
return value;
|
|
86313
|
+
}
|
|
86314
|
+
function clampQuality(value) {
|
|
86315
|
+
return Math.max(1, Math.min(100, Math.round(value)));
|
|
86316
|
+
}
|
|
86317
|
+
var DEFAULT_IMAGE_DELIVERY_SPEC, MAX_INPUT_PIXELS, INPUT_FORMATS, DEFAULT_MAX_DIMENSION, DEFAULT_MIN_DIMENSION, DEFAULT_INITIAL_QUALITY, DEFAULT_MIN_QUALITY;
|
|
86318
|
+
var init_image_delivery = __esm({
|
|
86319
|
+
"../server/src/domain/publishing/image-delivery.ts"() {
|
|
86320
|
+
"use strict";
|
|
86321
|
+
DEFAULT_IMAGE_DELIVERY_SPEC = {
|
|
86322
|
+
maxBytes: 10 * 1024 * 1024,
|
|
86323
|
+
allowedFormats: ["jpeg", "png", "webp", "gif"],
|
|
86324
|
+
allowTransparency: true,
|
|
86325
|
+
maxDimension: 2048,
|
|
86326
|
+
minDimension: 320
|
|
86327
|
+
};
|
|
86328
|
+
MAX_INPUT_PIXELS = 64e6;
|
|
86329
|
+
INPUT_FORMATS = /* @__PURE__ */ new Set(["jpeg", "png", "webp", "gif"]);
|
|
86330
|
+
DEFAULT_MAX_DIMENSION = 2048;
|
|
86331
|
+
DEFAULT_MIN_DIMENSION = 320;
|
|
86332
|
+
DEFAULT_INITIAL_QUALITY = 85;
|
|
86333
|
+
DEFAULT_MIN_QUALITY = 55;
|
|
86334
|
+
}
|
|
86335
|
+
});
|
|
86336
|
+
|
|
86066
86337
|
// ../server/src/domain/publishing/domain.ts
|
|
86067
86338
|
var init_domain3 = __esm({
|
|
86068
86339
|
"../server/src/domain/publishing/domain.ts"() {
|
|
@@ -86073,6 +86344,7 @@ var init_domain3 = __esm({
|
|
|
86073
86344
|
// ../server/src/domain/publishing/publication-runner.ts
|
|
86074
86345
|
async function freezePreparedPublication({
|
|
86075
86346
|
input,
|
|
86347
|
+
preparationKey,
|
|
86076
86348
|
contentPackage,
|
|
86077
86349
|
destination,
|
|
86078
86350
|
account,
|
|
@@ -86092,6 +86364,7 @@ async function freezePreparedPublication({
|
|
|
86092
86364
|
return {
|
|
86093
86365
|
id: `prepared_${checksum.slice(0, 24)}`,
|
|
86094
86366
|
checksum,
|
|
86367
|
+
preparationKey,
|
|
86095
86368
|
...semanticPayload,
|
|
86096
86369
|
accountRevision: account.revision,
|
|
86097
86370
|
createdAt
|
|
@@ -86193,7 +86466,7 @@ var init_publication_runner = __esm({
|
|
|
86193
86466
|
}
|
|
86194
86467
|
now;
|
|
86195
86468
|
maxConcurrency;
|
|
86196
|
-
async publish(request, task) {
|
|
86469
|
+
async publish(request, task, executionOptions) {
|
|
86197
86470
|
if (!await verifyContentPackageChecksum(request.contentPackage)) {
|
|
86198
86471
|
throw new Error(`\u5185\u5BB9\u5305 ${request.contentPackage.id} \u5B8C\u6574\u6027\u6821\u9A8C\u5931\u8D25`);
|
|
86199
86472
|
}
|
|
@@ -86247,7 +86520,8 @@ var init_publication_runner = __esm({
|
|
|
86247
86520
|
adapter,
|
|
86248
86521
|
model,
|
|
86249
86522
|
image,
|
|
86250
|
-
task.scope(`destination:${destination.id}`)
|
|
86523
|
+
task.scope(`destination:${destination.id}`),
|
|
86524
|
+
executionOptions
|
|
86251
86525
|
);
|
|
86252
86526
|
}
|
|
86253
86527
|
);
|
|
@@ -86258,7 +86532,7 @@ var init_publication_runner = __esm({
|
|
|
86258
86532
|
destinations: results
|
|
86259
86533
|
};
|
|
86260
86534
|
}
|
|
86261
|
-
async publishDestination(request, destination, account, adapter, model, image, task) {
|
|
86535
|
+
async publishDestination(request, destination, account, adapter, model, image, task, executionOptions) {
|
|
86262
86536
|
const existingReceipt = await this.options.lookupReceipt?.(
|
|
86263
86537
|
request.contentPackage.id,
|
|
86264
86538
|
destination.id
|
|
@@ -86278,65 +86552,80 @@ var init_publication_runner = __esm({
|
|
|
86278
86552
|
account,
|
|
86279
86553
|
options: { getStyle: this.options.resolveWritingStyle }
|
|
86280
86554
|
});
|
|
86281
|
-
|
|
86282
|
-
|
|
86283
|
-
|
|
86284
|
-
|
|
86285
|
-
|
|
86286
|
-
|
|
86287
|
-
|
|
86288
|
-
|
|
86555
|
+
const adapterFingerprint = await adapter.prepareFingerprint?.(destination, account);
|
|
86556
|
+
const preparationInput = {
|
|
86557
|
+
packageChecksum: request.contentPackage.checksum,
|
|
86558
|
+
...resolvedStyle ? { writingStyle: semanticWritingStyleSnapshot(resolvedStyle.style) } : {},
|
|
86559
|
+
...adapterFingerprint !== void 0 ? { adapterFingerprint } : {},
|
|
86560
|
+
destination,
|
|
86561
|
+
account: semanticAccountSnapshot(account),
|
|
86562
|
+
adapter: { id: adapter.id, version: adapter.version }
|
|
86563
|
+
};
|
|
86564
|
+
const preparationKey = await fingerprint(preparationInput);
|
|
86565
|
+
const lookupPrepared = executionOptions?.lookupPrepared ?? this.options.lookupPrepared;
|
|
86566
|
+
const reusable = lookupPrepared ? await lookupPrepared({
|
|
86567
|
+
packageId: request.contentPackage.id,
|
|
86568
|
+
destinationId: destination.id,
|
|
86569
|
+
preparationKey
|
|
86570
|
+
}) : void 0;
|
|
86571
|
+
if (reusable && reusable.preparationKey === preparationKey && reusable.packageChecksum === request.contentPackage.checksum && reusable.destinationId === destination.id && reusable.accountId === account.id && reusable.adapterId === adapter.id && reusable.adapterVersion === adapter.version) {
|
|
86572
|
+
prepared = reusable;
|
|
86573
|
+
} else {
|
|
86574
|
+
let effectivePackage = request.contentPackage;
|
|
86575
|
+
let adaptation;
|
|
86576
|
+
if (resolvedStyle) {
|
|
86577
|
+
if (!model) {
|
|
86578
|
+
throw new Error("\u542F\u7528\u5199\u4F5C\u98CE\u683C\u6539\u5199\u9700\u8981\u53EF\u7528\u7684\u5BF9\u8BDD\u6A21\u578B\u8FDE\u63A5");
|
|
86579
|
+
}
|
|
86580
|
+
const styleSnapshot = semanticWritingStyleSnapshot(resolvedStyle.style);
|
|
86581
|
+
const adapted = await task.run(
|
|
86582
|
+
{
|
|
86583
|
+
id: "adapt",
|
|
86584
|
+
version: "1",
|
|
86585
|
+
input: {
|
|
86586
|
+
packageChecksum: request.contentPackage.checksum,
|
|
86587
|
+
writingStyle: styleSnapshot
|
|
86588
|
+
}
|
|
86589
|
+
},
|
|
86590
|
+
(signal, adaptTask) => adaptContentForWritingStyle({
|
|
86591
|
+
contentPackage: request.contentPackage,
|
|
86592
|
+
writingStyle: resolvedStyle.style,
|
|
86593
|
+
model,
|
|
86594
|
+
signal,
|
|
86595
|
+
traceId: adaptTask.jobId,
|
|
86596
|
+
taskId: adaptTask.taskId
|
|
86597
|
+
})
|
|
86598
|
+
);
|
|
86599
|
+
adaptation = adapted.adaptation;
|
|
86600
|
+
effectivePackage = {
|
|
86601
|
+
...request.contentPackage,
|
|
86602
|
+
source: adapted.source,
|
|
86603
|
+
document: adapted.document
|
|
86604
|
+
};
|
|
86605
|
+
}
|
|
86606
|
+
const input = await task.run(
|
|
86289
86607
|
{
|
|
86290
|
-
id: "
|
|
86291
|
-
version:
|
|
86292
|
-
input:
|
|
86293
|
-
packageChecksum: request.contentPackage.checksum,
|
|
86294
|
-
writingStyle: styleSnapshot
|
|
86295
|
-
}
|
|
86608
|
+
id: "prepare",
|
|
86609
|
+
version: adapter.version,
|
|
86610
|
+
input: preparationInput
|
|
86296
86611
|
},
|
|
86297
|
-
(
|
|
86298
|
-
|
|
86299
|
-
writingStyle: resolvedStyle.style,
|
|
86612
|
+
async () => adapter.prepare(effectivePackage, destination, account, {
|
|
86613
|
+
task: task.scope("prepare-internal"),
|
|
86300
86614
|
model,
|
|
86301
|
-
|
|
86302
|
-
|
|
86303
|
-
taskId: adaptTask.taskId
|
|
86615
|
+
image,
|
|
86616
|
+
now: this.now
|
|
86304
86617
|
})
|
|
86305
86618
|
);
|
|
86306
|
-
|
|
86307
|
-
|
|
86308
|
-
|
|
86309
|
-
|
|
86310
|
-
|
|
86311
|
-
|
|
86619
|
+
prepared = await freezePreparedPublication({
|
|
86620
|
+
input: adaptation ? { ...input, adaptation } : input,
|
|
86621
|
+
preparationKey,
|
|
86622
|
+
contentPackage: request.contentPackage,
|
|
86623
|
+
destination,
|
|
86624
|
+
account,
|
|
86625
|
+
adapter,
|
|
86626
|
+
createdAt: this.now().toISOString()
|
|
86627
|
+
});
|
|
86312
86628
|
}
|
|
86313
|
-
const input = await task.run(
|
|
86314
|
-
{
|
|
86315
|
-
id: "prepare",
|
|
86316
|
-
version: adapter.version,
|
|
86317
|
-
input: {
|
|
86318
|
-
packageChecksum: request.contentPackage.checksum,
|
|
86319
|
-
...resolvedStyle ? { writingStyle: semanticWritingStyleSnapshot(resolvedStyle.style) } : {},
|
|
86320
|
-
destination,
|
|
86321
|
-
account: semanticAccountSnapshot(account),
|
|
86322
|
-
adapter: { id: adapter.id, version: adapter.version }
|
|
86323
|
-
}
|
|
86324
|
-
},
|
|
86325
|
-
async () => adapter.prepare(effectivePackage, destination, account, {
|
|
86326
|
-
task: task.scope("prepare-internal"),
|
|
86327
|
-
model,
|
|
86328
|
-
image,
|
|
86329
|
-
now: this.now
|
|
86330
|
-
})
|
|
86331
|
-
);
|
|
86332
|
-
prepared = await freezePreparedPublication({
|
|
86333
|
-
input: adaptation ? { ...input, adaptation } : input,
|
|
86334
|
-
contentPackage: request.contentPackage,
|
|
86335
|
-
destination,
|
|
86336
|
-
account,
|
|
86337
|
-
adapter,
|
|
86338
|
-
createdAt: this.now().toISOString()
|
|
86339
|
-
});
|
|
86340
86629
|
} catch (error) {
|
|
86341
86630
|
return failedDestination(destination, account.id, errorMessage2(error));
|
|
86342
86631
|
}
|
|
@@ -86965,7 +87254,7 @@ function stringArrayMetadata(metadata, key) {
|
|
|
86965
87254
|
const value = metadata?.[key];
|
|
86966
87255
|
return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
86967
87256
|
}
|
|
86968
|
-
var WeixinChannelAdapter, FetchPublicationAssetLoader;
|
|
87257
|
+
var logger2, WEIXIN_COVER_IMAGE_SPEC, WEIXIN_CONTENT_IMAGE_SPEC, WeixinChannelAdapter, FetchPublicationAssetLoader;
|
|
86969
87258
|
var init_weixin2 = __esm({
|
|
86970
87259
|
"../server/src/domain/publishing/channels/weixin.ts"() {
|
|
86971
87260
|
"use strict";
|
|
@@ -86973,11 +87262,30 @@ var init_weixin2 = __esm({
|
|
|
86973
87262
|
init_connectors2();
|
|
86974
87263
|
init_src();
|
|
86975
87264
|
init_runtime2();
|
|
87265
|
+
init_logging();
|
|
86976
87266
|
init_storage();
|
|
86977
87267
|
init_article_html_renderer();
|
|
86978
87268
|
init_layout_policy();
|
|
86979
87269
|
init_weixin_preparation_agent();
|
|
86980
87270
|
init_weixin_profile();
|
|
87271
|
+
init_image_delivery();
|
|
87272
|
+
logger2 = new Logger("weixin");
|
|
87273
|
+
WEIXIN_COVER_IMAGE_SPEC = {
|
|
87274
|
+
maxBytes: 10 * 1024 * 1024,
|
|
87275
|
+
targetBytes: 500 * 1024,
|
|
87276
|
+
allowedFormats: ["jpeg", "png"],
|
|
87277
|
+
allowTransparency: false,
|
|
87278
|
+
maxDimension: 2048,
|
|
87279
|
+
minDimension: 320
|
|
87280
|
+
};
|
|
87281
|
+
WEIXIN_CONTENT_IMAGE_SPEC = {
|
|
87282
|
+
maxBytes: 1024 * 1024 - 1,
|
|
87283
|
+
targetBytes: 800 * 1024,
|
|
87284
|
+
allowedFormats: ["jpeg", "png"],
|
|
87285
|
+
allowTransparency: true,
|
|
87286
|
+
maxDimension: 2048,
|
|
87287
|
+
minDimension: 320
|
|
87288
|
+
};
|
|
86981
87289
|
WeixinChannelAdapter = class {
|
|
86982
87290
|
constructor(options2) {
|
|
86983
87291
|
this.options = options2;
|
|
@@ -86986,6 +87294,18 @@ var init_weixin2 = __esm({
|
|
|
86986
87294
|
version = "4";
|
|
86987
87295
|
channel = ChannelId.WeixinOfficialAccount;
|
|
86988
87296
|
publicationType = WEIXIN_ARTICLE_PROFILE.definition.type;
|
|
87297
|
+
async prepareFingerprint(destination, account) {
|
|
87298
|
+
const layout = await resolvePublicationLayout({
|
|
87299
|
+
destination,
|
|
87300
|
+
account,
|
|
87301
|
+
options: { getTemplate: this.options.resolveTemplate ?? (async () => null) }
|
|
87302
|
+
});
|
|
87303
|
+
return {
|
|
87304
|
+
outputMode: layout.outputMode,
|
|
87305
|
+
templateChecksum: layout.templateChecksum,
|
|
87306
|
+
prompt: layout.prompt
|
|
87307
|
+
};
|
|
87308
|
+
}
|
|
86989
87309
|
async prepare(contentPackage, destination, account, context) {
|
|
86990
87310
|
const publicationType = destination.publicationType;
|
|
86991
87311
|
if (publicationType !== WEIXIN_ARTICLE_PROFILE.definition.type) {
|
|
@@ -87138,16 +87458,33 @@ var init_weixin2 = __esm({
|
|
|
87138
87458
|
if (!await verifyContentAssetChecksum(loaded.bytes, asset.checksum)) {
|
|
87139
87459
|
throw new Error(`\u8D44\u6E90 ${asset.id} \u7684 SHA-256 \u6821\u9A8C\u5931\u8D25\uFF0C\u5DF2\u62D2\u7EDD\u4E0A\u4F20`);
|
|
87140
87460
|
}
|
|
87141
|
-
const
|
|
87142
|
-
|
|
87461
|
+
const spec = role === "cover" ? WEIXIN_COVER_IMAGE_SPEC : WEIXIN_CONTENT_IMAGE_SPEC;
|
|
87462
|
+
try {
|
|
87463
|
+
const prepared = await prepareImageForDelivery(loaded, spec, signal);
|
|
87464
|
+
logger2.info("\u5FAE\u4FE1\u56FE\u7247\u9884\u5904\u7406\u5B8C\u6210", {
|
|
87465
|
+
assetId: asset.id,
|
|
87466
|
+
role,
|
|
87467
|
+
result: prepared.transformed ? "reencoded" : "unchanged",
|
|
87468
|
+
originalBytes: prepared.originalBytes,
|
|
87469
|
+
uploadBytes: prepared.uploadBytes,
|
|
87470
|
+
width: prepared.width,
|
|
87471
|
+
height: prepared.height,
|
|
87472
|
+
mimeType: prepared.asset.mimeType
|
|
87473
|
+
});
|
|
87474
|
+
return prepared.asset;
|
|
87475
|
+
} catch (error) {
|
|
87476
|
+
const reason = describeUnknown(error);
|
|
87477
|
+
logger2.warn("\u5FAE\u4FE1\u56FE\u7247\u9884\u5904\u7406\u5931\u8D25", {
|
|
87478
|
+
assetId: asset.id,
|
|
87479
|
+
role,
|
|
87480
|
+
originalBytes: loaded.bytes.byteLength,
|
|
87481
|
+
reason
|
|
87482
|
+
});
|
|
87143
87483
|
throw new Error(
|
|
87144
|
-
role === "cover" ? "\u5C01\u9762
|
|
87484
|
+
`\u5FAE\u4FE1${role === "cover" ? "\u5C01\u9762" : "\u6B63\u6587"}\u56FE\u7247 ${asset.id} \u9884\u5904\u7406\u5931\u8D25\uFF1A${reason}`,
|
|
87485
|
+
{ cause: error }
|
|
87145
87486
|
);
|
|
87146
87487
|
}
|
|
87147
|
-
return {
|
|
87148
|
-
...loaded,
|
|
87149
|
-
sourceUrl: /^https?:\/\//i.test(asset.source.uri) ? asset.source.uri : void 0
|
|
87150
|
-
};
|
|
87151
87488
|
}
|
|
87152
87489
|
};
|
|
87153
87490
|
FetchPublicationAssetLoader = class {
|
|
@@ -87358,19 +87695,16 @@ async function callExternalEffect2(fn2) {
|
|
|
87358
87695
|
throw error;
|
|
87359
87696
|
}
|
|
87360
87697
|
}
|
|
87361
|
-
async function loadVerifiedAsset(loader, asset, signal,
|
|
87698
|
+
async function loadVerifiedAsset(loader, asset, signal, specOrMaxBytes = DEFAULT_IMAGE_DELIVERY_SPEC) {
|
|
87362
87699
|
const loaded = await loader.load(asset, signal);
|
|
87363
87700
|
if (!await verifyContentAssetChecksum(loaded.bytes, asset.checksum)) {
|
|
87364
87701
|
throw new Error(`\u8D44\u6E90 ${asset.id} \u7684 SHA-256 \u6821\u9A8C\u5931\u8D25\uFF0C\u5DF2\u62D2\u7EDD\u4E0A\u4F20`);
|
|
87365
87702
|
}
|
|
87366
|
-
|
|
87367
|
-
|
|
87368
|
-
`\u8D44\u6E90 ${asset.id} \u8D85\u8FC7\u76EE\u6807\u5E73\u53F0\u5927\u5C0F\u9650\u5236\uFF08\u6700\u5927 ${Math.round(maxBytes / 1024 / 1024)} MB\uFF09`
|
|
87369
|
-
);
|
|
87370
|
-
}
|
|
87703
|
+
const spec = typeof specOrMaxBytes === "number" ? { ...DEFAULT_IMAGE_DELIVERY_SPEC, maxBytes: specOrMaxBytes } : specOrMaxBytes;
|
|
87704
|
+
const prepared = await prepareImageForDelivery(loaded, spec, signal);
|
|
87371
87705
|
return {
|
|
87372
|
-
...
|
|
87373
|
-
sourceUrl: asset.source.uri.startsWith("http") ? asset.source.uri : void 0
|
|
87706
|
+
...prepared.asset,
|
|
87707
|
+
sourceUrl: !prepared.transformed && asset.source.uri.startsWith("http") ? asset.source.uri : void 0
|
|
87374
87708
|
};
|
|
87375
87709
|
}
|
|
87376
87710
|
function pickCoverAsset(contentPackage) {
|
|
@@ -87836,6 +88170,7 @@ var init_standard_channel = __esm({
|
|
|
87836
88170
|
init_connectors2();
|
|
87837
88171
|
init_runtime2();
|
|
87838
88172
|
init_article_html_renderer();
|
|
88173
|
+
init_image_delivery();
|
|
87839
88174
|
}
|
|
87840
88175
|
});
|
|
87841
88176
|
|
|
@@ -88968,13 +89303,20 @@ function createGlobalChannelRegistrations(options2) {
|
|
|
88968
89303
|
}
|
|
88969
89304
|
];
|
|
88970
89305
|
}
|
|
88971
|
-
var BLUESKY_CHANNEL_DEFINITION, BLUESKY_POST_PROFILE, BlueskyChannelAdapter, MASTODON_CHANNEL_DEFINITION, MASTODON_POST_PROFILE, MastodonChannelAdapter, DEVTO_CHANNEL_DEFINITION, DEVTO_ARTICLE_PROFILE, DevtoChannelAdapter, HASHNODE_CHANNEL_DEFINITION, HASHNODE_ARTICLE_PROFILE, HashnodeChannelAdapter;
|
|
89306
|
+
var BLUESKY_IMAGE_SPEC, BLUESKY_CHANNEL_DEFINITION, BLUESKY_POST_PROFILE, BlueskyChannelAdapter, MASTODON_CHANNEL_DEFINITION, MASTODON_POST_PROFILE, MastodonChannelAdapter, DEVTO_CHANNEL_DEFINITION, DEVTO_ARTICLE_PROFILE, DevtoChannelAdapter, HASHNODE_CHANNEL_DEFINITION, HASHNODE_ARTICLE_PROFILE, HashnodeChannelAdapter;
|
|
88972
89307
|
var init_global_channels = __esm({
|
|
88973
89308
|
"../server/src/domain/publishing/channels/global-channels.ts"() {
|
|
88974
89309
|
"use strict";
|
|
88975
89310
|
init_src();
|
|
88976
89311
|
init_runtime2();
|
|
88977
89312
|
init_standard_channel();
|
|
89313
|
+
BLUESKY_IMAGE_SPEC = {
|
|
89314
|
+
maxBytes: 950 * 1024,
|
|
89315
|
+
allowedFormats: ["jpeg", "png", "webp"],
|
|
89316
|
+
allowTransparency: true,
|
|
89317
|
+
maxDimension: 2048,
|
|
89318
|
+
minDimension: 320
|
|
89319
|
+
};
|
|
88978
89320
|
BLUESKY_CHANNEL_DEFINITION = {
|
|
88979
89321
|
id: ChannelId.Bluesky,
|
|
88980
89322
|
name: "Bluesky",
|
|
@@ -89032,7 +89374,12 @@ var init_global_channels = __esm({
|
|
|
89032
89374
|
async (signal) => callExternalEffect2(
|
|
89033
89375
|
async () => client.uploadBlob(
|
|
89034
89376
|
session.accessJwt,
|
|
89035
|
-
await loadVerifiedAsset(
|
|
89377
|
+
await loadVerifiedAsset(
|
|
89378
|
+
this.options.assetLoader,
|
|
89379
|
+
cover,
|
|
89380
|
+
signal,
|
|
89381
|
+
BLUESKY_IMAGE_SPEC
|
|
89382
|
+
),
|
|
89036
89383
|
{ signal, traceId: context.task.jobId }
|
|
89037
89384
|
)
|
|
89038
89385
|
)
|
|
@@ -89781,21 +90128,42 @@ async function savePublicationRecord(workspace2, payload, now) {
|
|
|
89781
90128
|
createWorkspaceEntity2(payload, now)
|
|
89782
90129
|
);
|
|
89783
90130
|
}
|
|
90131
|
+
const mergedBatch = {
|
|
90132
|
+
...payload.batch,
|
|
90133
|
+
destinations: payload.batch.destinations.map((dest) => {
|
|
90134
|
+
if (dest.prepared) return dest;
|
|
90135
|
+
const prior = existing.batch.destinations.find(
|
|
90136
|
+
(item) => item.destinationId === dest.destinationId
|
|
90137
|
+
);
|
|
90138
|
+
return prior?.prepared ? { ...dest, prepared: prior.prepared } : dest;
|
|
90139
|
+
})
|
|
90140
|
+
};
|
|
90141
|
+
const mergedPayload = { ...payload, batch: mergedBatch };
|
|
89784
90142
|
const existingPayload = {
|
|
89785
90143
|
id: existing.id,
|
|
89786
90144
|
jobId: existing.jobId,
|
|
89787
90145
|
packageId: existing.packageId,
|
|
89788
90146
|
batch: existing.batch
|
|
89789
90147
|
};
|
|
89790
|
-
if (stableStringify(existingPayload) === stableStringify(
|
|
90148
|
+
if (stableStringify(existingPayload) === stableStringify(mergedPayload)) {
|
|
89791
90149
|
return existing;
|
|
89792
90150
|
}
|
|
89793
|
-
const { id: _id, ...patch } =
|
|
90151
|
+
const { id: _id, ...patch } = mergedPayload;
|
|
89794
90152
|
return await workspace2.save(
|
|
89795
90153
|
WorkspaceKind.Publication,
|
|
89796
90154
|
reviseWorkspaceEntity2(existing, patch, now)
|
|
89797
90155
|
);
|
|
89798
90156
|
}
|
|
90157
|
+
async function lookupPreparedPublication(workspace2, query) {
|
|
90158
|
+
const publications2 = (await workspace2.list(WorkspaceKind.Publication)).filter((publication) => publication.packageId === query.packageId).sort((left, right) => right.updatedAt.localeCompare(left.updatedAt));
|
|
90159
|
+
for (const publication of publications2) {
|
|
90160
|
+
const match2 = publication.batch.destinations.find(
|
|
90161
|
+
(item) => item.destinationId === query.destinationId && item.prepared?.preparationKey === query.preparationKey
|
|
90162
|
+
);
|
|
90163
|
+
if (match2?.prepared) return match2.prepared;
|
|
90164
|
+
}
|
|
90165
|
+
return void 0;
|
|
90166
|
+
}
|
|
89799
90167
|
var PublishingApplication;
|
|
89800
90168
|
var init_publishing_application = __esm({
|
|
89801
90169
|
"../server/src/domain/publishing/publishing-application.ts"() {
|
|
@@ -89955,13 +90323,18 @@ var init_publishing_application = __esm({
|
|
|
89955
90323
|
return await toPublishingDestination(selection, account);
|
|
89956
90324
|
})
|
|
89957
90325
|
);
|
|
90326
|
+
const parent = job.parentJobId ? await this.options.jobs.get(job.parentJobId) : null;
|
|
90327
|
+
const isRetry = parent?.type === JobType.PublishContent;
|
|
89958
90328
|
const batch = await this.options.publishing.publish(
|
|
89959
90329
|
{
|
|
89960
90330
|
contentPackage: storedPackage.contentPackage,
|
|
89961
90331
|
destinations,
|
|
89962
90332
|
accounts: resolvedAccounts.map(toPublishingAccount)
|
|
89963
90333
|
},
|
|
89964
|
-
this.taskRunner.forJob(job.id)
|
|
90334
|
+
this.taskRunner.forJob(job.id),
|
|
90335
|
+
isRetry ? {
|
|
90336
|
+
lookupPrepared: (query) => lookupPreparedPublication(this.options.workspace, query)
|
|
90337
|
+
} : void 0
|
|
89965
90338
|
);
|
|
89966
90339
|
const publication = await savePublicationRecord(
|
|
89967
90340
|
this.options.workspace,
|
|
@@ -90007,6 +90380,7 @@ var init_publishing2 = __esm({
|
|
|
90007
90380
|
init_writing_style_extraction();
|
|
90008
90381
|
init_content_adapter();
|
|
90009
90382
|
init_image_asset();
|
|
90383
|
+
init_image_delivery();
|
|
90010
90384
|
init_domain3();
|
|
90011
90385
|
init_publication_runner();
|
|
90012
90386
|
init_article_html_renderer();
|
|
@@ -95995,7 +96369,7 @@ function jsonValidator(result, c3) {
|
|
|
95995
96369
|
function unauthorizedResponse(c3) {
|
|
95996
96370
|
return c3.json({ error: "\u672A\u6388\u6743\u7684\u8BBF\u95EE" }, 401);
|
|
95997
96371
|
}
|
|
95998
|
-
var
|
|
96372
|
+
var logger3, HttpError, errorMapper;
|
|
95999
96373
|
var init_errors5 = __esm({
|
|
96000
96374
|
"../server/src/http/middleware/errors.ts"() {
|
|
96001
96375
|
"use strict";
|
|
@@ -96004,7 +96378,7 @@ var init_errors5 = __esm({
|
|
|
96004
96378
|
init_connectors2();
|
|
96005
96379
|
init_workspace3();
|
|
96006
96380
|
init_zod();
|
|
96007
|
-
|
|
96381
|
+
logger3 = new Logger("http");
|
|
96008
96382
|
HttpError = class extends Error {
|
|
96009
96383
|
constructor(message, status = 400) {
|
|
96010
96384
|
super(message);
|
|
@@ -96040,7 +96414,7 @@ var init_errors5 = __esm({
|
|
|
96040
96414
|
error.kind === "configuration" || error.kind === "invalid_request" ? 400 : 502
|
|
96041
96415
|
);
|
|
96042
96416
|
}
|
|
96043
|
-
|
|
96417
|
+
logger3.error("\u672A\u6355\u83B7\u7684\u8DEF\u7531\u5F02\u5E38:", error);
|
|
96044
96418
|
const message = error instanceof Error ? error.message : String(error);
|
|
96045
96419
|
return c3.json(
|
|
96046
96420
|
{
|
|
@@ -96091,13 +96465,13 @@ var init_auth = __esm({
|
|
|
96091
96465
|
function cryptoRandomId() {
|
|
96092
96466
|
return `req-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
96093
96467
|
}
|
|
96094
|
-
var
|
|
96468
|
+
var logger4, requestContext;
|
|
96095
96469
|
var init_logger3 = __esm({
|
|
96096
96470
|
"../server/src/http/middleware/logger.ts"() {
|
|
96097
96471
|
"use strict";
|
|
96098
96472
|
init_deps();
|
|
96099
96473
|
init_logging();
|
|
96100
|
-
|
|
96474
|
+
logger4 = new Logger("http-request");
|
|
96101
96475
|
requestContext = factory.createMiddleware(async (c3, next) => {
|
|
96102
96476
|
const requestId = c3.req.header("X-Request-Id") ?? cryptoRandomId();
|
|
96103
96477
|
c3.set("requestId", requestId);
|
|
@@ -96110,14 +96484,14 @@ var init_logger3 = __esm({
|
|
|
96110
96484
|
} finally {
|
|
96111
96485
|
const status = c3.res.status;
|
|
96112
96486
|
const ms2 = Date.now() - start;
|
|
96113
|
-
|
|
96487
|
+
logger4.info(`${method} ${path8} -> ${status} (${ms2}ms) requestId=${requestId}`);
|
|
96114
96488
|
}
|
|
96115
96489
|
});
|
|
96116
96490
|
}
|
|
96117
96491
|
});
|
|
96118
96492
|
|
|
96119
96493
|
// ../../node_modules/.pnpm/hono@4.13.23/node_modules/hono/dist/utils/cookie.js
|
|
96120
|
-
var relaxedCookieNameRegEx, validCookieValueRegEx, trimCookieWhitespace,
|
|
96494
|
+
var relaxedCookieNameRegEx, validCookieValueRegEx, trimCookieWhitespace, parse3;
|
|
96121
96495
|
var init_cookie = __esm({
|
|
96122
96496
|
"../../node_modules/.pnpm/hono@4.13.23/node_modules/hono/dist/utils/cookie.js"() {
|
|
96123
96497
|
init_url();
|
|
@@ -96138,7 +96512,7 @@ var init_cookie = __esm({
|
|
|
96138
96512
|
}
|
|
96139
96513
|
return start === 0 && end === value.length ? value : value.slice(start, end);
|
|
96140
96514
|
};
|
|
96141
|
-
|
|
96515
|
+
parse3 = (cookie, name) => {
|
|
96142
96516
|
if (name && cookie.indexOf(name) === -1) return {};
|
|
96143
96517
|
const pairs = cookie.split(";");
|
|
96144
96518
|
const parsedCookie = /* @__PURE__ */ Object.create(null);
|
|
@@ -96171,10 +96545,10 @@ var init_cookie2 = __esm({
|
|
|
96171
96545
|
let finalKey = key;
|
|
96172
96546
|
if (prefix === "secure") finalKey = "__Secure-" + key;
|
|
96173
96547
|
else if (prefix === "host") finalKey = "__Host-" + key;
|
|
96174
|
-
return
|
|
96548
|
+
return parse3(cookie, finalKey)[finalKey];
|
|
96175
96549
|
}
|
|
96176
96550
|
if (!cookie) return {};
|
|
96177
|
-
return
|
|
96551
|
+
return parse3(cookie);
|
|
96178
96552
|
};
|
|
96179
96553
|
}
|
|
96180
96554
|
});
|
|
@@ -96464,7 +96838,7 @@ function startEntitlementSync(connections2, intervalMs = 6 * 60 * 60 * 1e3) {
|
|
|
96464
96838
|
if (!issuer) return () => void 0;
|
|
96465
96839
|
const sync = () => {
|
|
96466
96840
|
void runEntitlementSync({ issuer, connections: connections2 }).catch((error) => {
|
|
96467
|
-
|
|
96841
|
+
logger5.warn("entitlement \u540C\u6B65\u5931\u8D25:", error instanceof Error ? error.message : String(error));
|
|
96468
96842
|
});
|
|
96469
96843
|
};
|
|
96470
96844
|
sync();
|
|
@@ -96472,14 +96846,14 @@ function startEntitlementSync(connections2, intervalMs = 6 * 60 * 60 * 1e3) {
|
|
|
96472
96846
|
timer.unref?.();
|
|
96473
96847
|
return () => clearInterval(timer);
|
|
96474
96848
|
}
|
|
96475
|
-
var
|
|
96849
|
+
var logger5, REFRESH_THRESHOLD_MS, WEIXIN_RELAY_CONNECTOR;
|
|
96476
96850
|
var init_entitlement_sync = __esm({
|
|
96477
96851
|
"../server/src/relay/entitlement-sync.ts"() {
|
|
96478
96852
|
"use strict";
|
|
96479
96853
|
init_logging();
|
|
96480
96854
|
init_credential();
|
|
96481
96855
|
init_oauth();
|
|
96482
|
-
|
|
96856
|
+
logger5 = new Logger("relay-entitlement");
|
|
96483
96857
|
REFRESH_THRESHOLD_MS = 24 * 60 * 60 * 1e3;
|
|
96484
96858
|
WEIXIN_RELAY_CONNECTOR = "weixin-relay";
|
|
96485
96859
|
}
|
|
@@ -98554,8 +98928,8 @@ var init_executions = __esm({
|
|
|
98554
98928
|
// ../server/src/shared/utils/server-version.ts
|
|
98555
98929
|
import { readFileSync as readFileSync3 } from "node:fs";
|
|
98556
98930
|
function resolveServerVersion() {
|
|
98557
|
-
if ("4.0.0-beta.
|
|
98558
|
-
return "4.0.0-beta.
|
|
98931
|
+
if ("4.0.0-beta.3".length > 0) {
|
|
98932
|
+
return "4.0.0-beta.3";
|
|
98559
98933
|
}
|
|
98560
98934
|
try {
|
|
98561
98935
|
const raw2 = readFileSync3(new URL("../../../../../package.json", import.meta.url), "utf8");
|
|
@@ -100124,7 +100498,7 @@ var init_runs = __esm({
|
|
|
100124
100498
|
throw new HttpError("\u8BE5\u76EE\u7684\u5730\u5B58\u5728\u672A\u786E\u8BA4\u5916\u90E8\u526F\u4F5C\u7528\uFF0C\u4E0D\u80FD\u81EA\u52A8\u91CD\u8BD5", 409);
|
|
100125
100499
|
}
|
|
100126
100500
|
const sourceJobs = await Promise.all(session.jobIds.map((id) => runtime.jobs.get(id)));
|
|
100127
|
-
const source = sourceJobs.
|
|
100501
|
+
const source = sourceJobs.findLast((job2) => job2?.type === JobType.PublishContent);
|
|
100128
100502
|
const selection = source?.input.destinations.find(
|
|
100129
100503
|
(item) => item.accountId === session.destination?.accountId && item.publicationType === session.destination?.publicationType
|
|
100130
100504
|
);
|
|
@@ -100164,7 +100538,7 @@ var init_runs = __esm({
|
|
|
100164
100538
|
throw new HttpError("\u53EA\u6709\u9700\u8981\u4EBA\u5DE5\u786E\u8BA4\u7684\u76EE\u7684\u5730\u624D\u80FD\u6838\u9500", 409);
|
|
100165
100539
|
}
|
|
100166
100540
|
const sourceJobs = await Promise.all(session.jobIds.map((id) => runtime.jobs.get(id)));
|
|
100167
|
-
const source = sourceJobs.
|
|
100541
|
+
const source = sourceJobs.findLast((job) => job?.type === JobType.PublishContent);
|
|
100168
100542
|
if (!source || !detail.run.packageId || !session.destination) {
|
|
100169
100543
|
throw new HttpError("\u65E0\u6CD5\u6062\u590D\u8BE5\u53D1\u5E03\u76EE\u7684\u5730\u7684\u8F93\u5165", 409);
|
|
100170
100544
|
}
|
|
@@ -100458,17 +100832,17 @@ async function startServer(port = 8e3) {
|
|
|
100458
100832
|
throw error;
|
|
100459
100833
|
}
|
|
100460
100834
|
server.on("error", (error) => {
|
|
100461
|
-
|
|
100835
|
+
logger6.error("HTTP \u670D\u52A1\u51FA\u9519:", error instanceof Error ? error.message : String(error));
|
|
100462
100836
|
});
|
|
100463
100837
|
let shuttingDown = false;
|
|
100464
100838
|
const shutdown = (signal) => {
|
|
100465
100839
|
if (shuttingDown) return;
|
|
100466
100840
|
shuttingDown = true;
|
|
100467
|
-
|
|
100841
|
+
logger6.info(`\u6536\u5230 ${signal}\uFF0C\u6B63\u5728\u4F18\u96C5\u5173\u95ED\u670D\u52A1\u2026`);
|
|
100468
100842
|
stopEntitlementSync();
|
|
100469
100843
|
runtime.scheduler.stop();
|
|
100470
100844
|
const forceExit = setTimeout(() => {
|
|
100471
|
-
|
|
100845
|
+
logger6.warn(`\u4F18\u96C5\u5173\u95ED\u8D85\u8FC7 ${SHUTDOWN_TIMEOUT_MS}ms\uFF0C\u5F3A\u5236\u9000\u51FA`);
|
|
100472
100846
|
runtime.close?.();
|
|
100473
100847
|
process.exit(1);
|
|
100474
100848
|
}, SHUTDOWN_TIMEOUT_MS);
|
|
@@ -100482,13 +100856,13 @@ async function startServer(port = 8e3) {
|
|
|
100482
100856
|
};
|
|
100483
100857
|
process.on("SIGINT", () => shutdown("SIGINT"));
|
|
100484
100858
|
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
|
100485
|
-
|
|
100486
|
-
|
|
100859
|
+
logger6.info(`\u670D\u52A1\u76D1\u542C\u5728 http://0.0.0.0:${port}`);
|
|
100860
|
+
logger6.info(`dashboard \u5730\u5740: http://localhost:${port}/dashboard`);
|
|
100487
100861
|
if (process.env.TRENDPUBLISH_DASHBOARD_DEV_SERVER_URL) {
|
|
100488
|
-
|
|
100862
|
+
logger6.info(`dashboard \u5F00\u53D1\u4EE3\u7406: ${process.env.TRENDPUBLISH_DASHBOARD_DEV_SERVER_URL}`);
|
|
100489
100863
|
}
|
|
100490
100864
|
}
|
|
100491
|
-
var
|
|
100865
|
+
var logger6, SHUTDOWN_TIMEOUT_MS, LocalDashboardAssetStore;
|
|
100492
100866
|
var init_server = __esm({
|
|
100493
100867
|
"../server/src/server.ts"() {
|
|
100494
100868
|
"use strict";
|
|
@@ -100502,7 +100876,7 @@ var init_server = __esm({
|
|
|
100502
100876
|
init_dashboard_routing();
|
|
100503
100877
|
init_logging();
|
|
100504
100878
|
init_entitlement_sync();
|
|
100505
|
-
|
|
100879
|
+
logger6 = new Logger("server");
|
|
100506
100880
|
SHUTDOWN_TIMEOUT_MS = 5e3;
|
|
100507
100881
|
LocalDashboardAssetStore = class {
|
|
100508
100882
|
constructor(distDir) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@becomeopc/trendpublish",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.3",
|
|
4
4
|
"description": "TrendPublish — 自托管内容生成与多渠道发布服务(CLI + 常驻后台 + Web Dashboard)",
|
|
5
5
|
"homepage": "https://github.com/liyown/ai-trend-publish#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"@aws-sdk/client-s3": "^3.901.0",
|
|
30
30
|
"better-sqlite3": "^13.2.0",
|
|
31
31
|
"pm2": "^7.1.2",
|
|
32
|
+
"sharp": "^0.35.6",
|
|
32
33
|
"undici": "^7.24.8"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|