@ginstone/nga-api
Version:
41 lines (40 loc) • 1.69 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Attachment = exports.THUMB_MAP = void 0;
const AttachmentUtils_1 = require("../../../utils/AttachmentUtils");
const StrUtils_1 = require("../../../utils/StrUtils");
const prefix = "https://img.nga.178.com/attachments/";
/**
* 缩略图bit数据, 位置与后缀的对应关系
*/
exports.THUMB_MAP = [
{ index: 3, suffix: ".thumb_ss.jpg" },
{ index: 4, suffix: ".thumb_s.jpg" },
{ index: 5, suffix: ".thumb.jpg" },
{ index: 6, suffix: ".medium.jpg" },
];
const ATTACH_PREFIX = '/attachments/';
class Attachment {
constructor(raw) {
this.url = raw.url || raw.attachurl || "";
this.absoluteUrl = this.url ? prefix + this.url : undefined;
this.description = raw.dscp;
this.extension = raw.ext ? raw.ext : (raw.name ? (0, StrUtils_1.getExtension)(raw.name) : undefined);
this.filename = raw.name;
this.path = raw.path;
this.size = raw.size;
this.type = raw.type;
this.originalFilename = raw.url_utf8_org_name ? decodeURI(raw.url_utf8_org_name) : undefined;
this.view = {
aid: this.filename,
extension: this.extension || '',
src: ATTACH_PREFIX + AttachmentUtils_1.AttachmentUtils.getImageUrls(this.url, raw.thumb)[0].url,
bbsCodes: AttachmentUtils_1.AttachmentUtils.getBbsCodes(this.url, raw.thumb, this.originalFilename),
description: this.description,
filename: this.originalFilename || this.filename || "",
url: ATTACH_PREFIX + this.url,
size: this.size || 0,
};
}
}
exports.Attachment = Attachment;