HCL Domino AppDevPack - 编写富文本的问题

HCL Domino AppDevPack - Problem with writing Rich Text

我用的是the code proposed as an example in the documentation for Domino AppDev Pack 1.0.4,唯一不同的是读取一个文本文件(body.txt)作为缓冲,这个文件只包含简单的长文本(40Ko)。

执行时,文档会在数据库中创建,其余代码不会return出错。 但是最终,富文本字段并没有添加到文档中。 这里的回复 returned:

response: {"fields":[{"fieldName":"Body","unid":"8EA69129BEECA6DEC1258554002F5DCD","error":{"name":"ProtonError","code":65577,"id":"RICH_TEXT_STREAM_CORRUPT"}}]}

我的目标是在富文本字段中编写非常长的文本(超过 64 Ko)。我在示例中使用了一个文本文件作为缓冲区,但稍后可能会像 const buffer = Buffer.from ('very long text ...')

这是正确的方法还是必须采用不同的方法?

我正在使用带有 IBM Domino (r) Server(64 位)版本 10.0.1FP4 和 AppDevPack 1.0.4 的 Windows 系统。

提前感谢您的帮助

代码如下:

const write = async (database) => {
  let writable;
  let result;
  try {
    // Create a document with subject write-example-1 to hold rich text
    const unid = await database.createDocument({
      document: {
        Form: 'RichDiscussion',
        Title: 'write-example-1',
      },
    });
    writable = await database.bulkCreateRichTextStream({});
    result = await new Promise((resolve, reject) => {
      // Set up event handlers.
      // Reject the Promise if there is a connection-level error.
      writable.on('error', (e) => {
        reject(e);
      });
      // Return the response from writing when resolving the Promise.
      writable.on('response', (response) => {
        console.log("response: " + JSON.stringify(response));
        resolve(response);
      });
      // Indicates which document and item name to use.
      writable.field({ unid, fieldName: 'Body' });
      let offset = 0;
      // Assume for purposes of this example that we buffer the entire file.
      const buffer = fs.readFileSync('/driver/body.txt');
      // When writing large amounts of data, it is necessary to
      // wait for the client-side to complete the previous write
      // before writing more data.
      const writeData = () => {
        let draining = true;
        while (offset < buffer.length && draining) {
          const remainingBytes = buffer.length - offset;
          let chunkSize = 16 * 1024;
          if (remainingBytes < chunkSize) {
            chunkSize = remainingBytes;
          }
          draining = writable.write(buffer.slice(offset, offset + chunkSize));
          offset += chunkSize;
        }
        if (offset < buffer.length) {
          // Buffer is not draining. Whenever the drain event is emitted
          // call this function again to write more data.
          writable.once('drain', writeData);
        }
      };
      writeData();
      writable = undefined;
    });
  } catch (e) {
    console.log(`Unexpected exception ${e.message}`);
  } finally {
    if (writable) {
      writable.end();
    }
  }
  return result;
};

从 appdev pack 1.0.4 开始,富文本流接受 LMBCS 字符集中有效的富文本 cd 格式的写入数据。我们目前正在开发一个库来帮助您将有效的富文本数据写入流。

我很想听听更多关于您的用例的信息,我们很高兴您已经开始使用该功能了!如果你能加入 openntf slack 频道,我通常会在那里闲逛。