Skip to content

Instantly share code, notes, and snippets.

@davidshimjs
Last active February 11, 2018 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidshimjs/af1d67804ae5e9f5080dc045a8df4268 to your computer and use it in GitHub Desktop.
Save davidshimjs/af1d67804ae5e9f5080dc045a8df4268 to your computer and use it in GitHub Desktop.
get.js로 메모 목록을 가져와서 공유하고, set.js로 공유받은 메모 목록을 설정하세요
$.ajax({
url: '/service/api/auth/memo/list',
dataType: 'json',
method: 'GET',
success: function (data) {
const map = {};
const output = [];
data.memoList.forEach(v => {
map[v.note] = map[v.note] || 0;
map[v.note]++;
output.push(`${v.note}|${v.destId}|${v.blockMessageYn ? 1 : 0}|${v.blockArticleYn ? 1 : 0}`);
});
const message = [];
message.push('공개된 장소에는 아래 내용을 복사해서 보여주시고, 실제 데이터는 공개된 장소에 절대 노출하지 말아주세요. 명예훼손이 성립될 수도 있습니다.');
message.push('메모 내역은 다음과 같습니다.');
for (let key in map) {
const value = map[key];
message.push(`${key}: ${value}건`);
}
message.push(`총 ${data.memoList.length}건.`);
message.push('---- (*) 여기부터는 절대 공개된 장소에 노출하지 말아주세요. 개인 쪽지 등으로만 데이터를 공유해 주세요 (*) ----');
console.log(message.join('\n'));
console.log(output.join('\n'));
}
});
(function () {
const data = `
// 이 위치에 데이터를 붙여주세요
멋진사람|ssm96|0|0
`;
const post = function (note, id, blockMessageYn, blockArticleYn) {
return new Promise(function (resolve, reject) {
$.ajax({
url: '/service/api/mypage/memo/block/' + id,
type: 'POST',
data: {
myUserMemo: JSON.stringify({ note, blockMessageYn, blockArticleYn })
},
success(result) {
resolve(result);
},
error(reason) {
reject(reason);
}
});
});
};
let promise = Promise.resolve();
let count = 0;
String(data).trim().split('\n').forEach(v => {
if (v.indexOf('//') === 0) {
return;
}
const [note, id, blockMessage, blockArticle] = String(v).trim().split('|');
const blockMessageYn = (blockMessage && blockMessage === '1') ? true : false;
const blockArticleYn = (blockArticle && blockArticle === '1') ? true : false;
promise = promise.then(() => {
return post(note, id, blockMessageYn, blockArticleYn);
}).then(() => {
count++;
console.log(`${id} 메모 입력`);
});
});
promise.then(() => {
console.log(`${count}개 입력 완료`);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment