|
本帖最后由 Typeboom 于 2024-12-29 23:07 编辑
别看了别看了,半天不到就删图
- try {
- if (img.size > 10 * 1024 * 1024) {
- throw new Error
- }
- let ticket = await utils.fetchWithTimeout(`https://lib.xmu.edu.cn/ask/problem_report?db_name=RESSET%E6%95%B0%E6%8D%AE%E5%BA%93%E7%B3%BB%E5%88%97`).then(r => r.text());
- ticket = ticket.split('\n')[53];
- ticket = JSON.parse(ticket.match(/jQuery\.extend\(Drupal\.settings,\s*({.+?})\);/s)[1]);
- const formID = `form-${ticket.ajax['edit-field-dbq-img-und-0-upload-button'].url.split('form-')[1]}`
- let form = new FormData();
- form.append(`form_build_id`, formID);
- form.append(`form_id`, `services_db_report_form`);
- form.append(`field_dbq_db_title[und][0][value]`, `RESSET数据库系列`);
- form.append('files[field_dbq_img_und_0]', fsc.createReadStream(img.path), img.name);
- form.append(`ajax_page_state[theme_token]`, ticket.ajaxPageState.theme_token);
- let upload = await utils.fetchWithTimeout(`https://lib.xmu.edu.cn/ask/zh-hans/file/ajax/field_dbq_img/und/${formID}`, {
- method: 'POST',
- body: form
- }, 10 * 1000).then(r => r.text());
- upload = upload.replace(/\\u([\d\w]{4})/gi, (match, grp) => {
- return String.fromCharCode(parseInt(grp, 16));
- });
- upload = decodeURIComponent(upload);
- const matches = upload.match(/https:\\\/\\\/lib\.xmu\.edu\.cn\\\/ask\\\/sites\\\/default\\\/files\\\/dbq\\\/[a-f0-9-]+\.(png|gif|jpg|jpeg)/g);
- if (!matches) {
- throw new Error
- }
- console.log(matches[0].replace(/\\/g, ''))
- } catch (error) {
- console.log(error)
- }
复制代码 |
|