use of io.github.ihongs.action.anno.Action in project HongsCORE by ihongs.
the class MineAction method mineInfo.
@Action("info")
@Preset(conf = "master", form = "mine")
public void mineInfo(ActionHelper ah) throws HongsException {
Object id = ah.getSessibute(Cnst.UID_SES);
if (id == null || "".equals(id)) {
throw new HongsException(401, "");
}
UserAction ua = new UserAction();
Map rd = ah.getRequestData();
rd.put("id", id);
ua.getInfo(ah);
}
use of io.github.ihongs.action.anno.Action in project HongsCORE by ihongs.
the class MineAction method sameName.
@Action("same")
@Preset(conf = "master", form = "mine")
public void sameName(ActionHelper ah) throws HongsException {
Object id = ah.getSessibute(Cnst.UID_SES);
if (id == null || "".equals(id)) {
throw new HongsException(401, "");
}
UserAction ua = new UserAction();
Map rd = ah.getRequestData();
rd.put("id", id);
ua.isUnique(ah);
}
use of io.github.ihongs.action.anno.Action in project HongsCORE by ihongs.
the class InfoAction method search.
@Action("search")
public void search(ActionHelper helper) throws HongsException {
Map rsp = new HashMap();
Map req = helper.getRequestData();
long now = System.currentTimeMillis();
Set rb = Synt.toTerms(req.get(Cnst.RB_KEY));
// 当前时间
rsp.put("now_msec", now);
// 应用信息
if (rb == null || rb.contains("app_info")) {
Map app = new HashMap();
rsp.put("app_info", app);
app.put("server_id", Core.SERVER_ID);
app.put("base_href", Core.SERV_HREF + Core.SERV_PATH);
app.put("core_path", Core.CORE_PATH);
app.put("starts_time", Core.STARTS_TIME);
app.put("system_zone", CoreConfig.getInstance().getProperty("core.timezone.default", Cnst.ZONE_DEF));
app.put("system_lang", CoreConfig.getInstance().getProperty("core.language.default", Cnst.LANG_DEF));
}
// 磁盘情况
if (rb == null || rb.contains("dir_info")) {
Map inf = new HashMap();
rsp.put("dir_info", inf);
inf.put("base_dir", getAllSize(new File(Core.BASE_PATH)));
inf.put("data_dir", getAllSize(new File(Core.DATA_PATH)));
inf.put("conf_dir", getAllSize(new File(Core.CONF_PATH)));
inf.put("core_dir", getAllSize(new File(Core.CORE_PATH)));
}
// 系统信息
if (rb == null || rb.contains("sys_info")) {
Map inf = new HashMap();
rsp.put("sys_info", inf);
Properties pps = System.getProperties();
inf.put("name", pps.getProperty("os.name") + " " + pps.getProperty("os.version"));
inf.put("java", pps.getProperty("java.specification.name") + " " + pps.getProperty("java.specification.version"));
inf.put("user", pps.getProperty("user.name"));
}
// 运行信息
if (rb == null || rb.contains("run_info")) {
OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
MemoryMXBean mm = ManagementFactory.getMemoryMXBean();
MemoryUsage nm = mm.getNonHeapMemoryUsage();
MemoryUsage hm = mm.getHeapMemoryUsage();
Runtime rt = Runtime.getRuntime();
double avg = os.getSystemLoadAverage();
long siz = rt.totalMemory();
long fre = rt.freeMemory();
long max = rt.maxMemory();
long stk = nm.getUsed();
long use = hm.getUsed();
Map inf = new HashMap();
rsp.put("run_info", inf);
inf.put("load", new Object[] { avg, String.valueOf(avg), "负载" });
inf.put("size", new Object[] { siz, Syno.humanSize(siz), "全部" });
inf.put("free", new Object[] { fre, Syno.humanSize(fre), "空闲" });
inf.put("dist", new Object[] { max, Syno.humanSize(max), "可用" });
inf.put("used", new Object[] { use, Syno.humanSize(use), "已用" });
inf.put("uses", new Object[] { stk, Syno.humanSize(stk), "非堆" });
}
/**
* 公共核心情况和锁情况
*/
if (rb != null && rb.contains("core_info")) {
rsp.put("core_info", new CoreToKeys(Core.GLOBAL_CORE).keySet());
}
if (rb != null && rb.contains("task_info")) {
rsp.put("task_info", getAllTasks());
}
if (rb != null && rb.contains("cron_info")) {
rsp.put("cron_info", getAllCrons());
}
if (rb != null && rb.contains("lock_info")) {
rsp.put("lock_info", Gate.counts());
}
helper.reply(Synt.mapOf("info", rsp));
}
use of io.github.ihongs.action.anno.Action in project HongsCORE by ihongs.
the class FileAction method create.
@Action("create")
public void create(ActionHelper helper) throws HongsException {
List list = new ArrayList();
List fils = Synt.asList(helper.getRequestData().get("file"));
String uid = Synt.declare(helper.getSessibute(Cnst.UID_SES), "0");
String nid = Core.newIdentity();
int idx = 0;
if (fils == null || fils.size() < 1) {
helper.reply(Synt.mapOf("ok", false, "ern", "Er400", "err", "file required"));
return;
}
if (fils.size() > 9) {
helper.reply(Synt.mapOf("ok", false, "ern", "Er400", "err", "up to 9 files"));
return;
}
UploadHelper uh = new UploadHelper();
uh.setUploadPath("static/upload/tmp");
uh.setUploadHref("static/upload/tmp");
for (Object item : fils) {
if (item instanceof Part) {
Part part = (Part) item;
String name = (uid + "-" + nid) + "-" + (idx++) + ".";
File file = uh.upload(part, name);
String href = uh.getResultHref();
String link = Core.SERVER_HREF.get() + Core.SERVER_PATH.get() + "/" + href;
name = file.getName() + "|" + part.getSubmittedFileName();
list.add(Synt.mapOf("name", name, "href", href, "link", link));
}
}
helper.reply(Synt.mapOf("list", list));
}
use of io.github.ihongs.action.anno.Action in project HongsCORE by ihongs.
the class FileAction method update.
@Override
@Action("update")
public void update(ActionHelper helper) throws HongsException {
CoreLocale lang = CoreLocale.getInstance("manage");
String path = helper.getParameter("path");
String dist = helper.getParameter("dist");
String text = helper.getParameter("text");
File file;
File dizt;
if (dist != null && dist.equals(path)) {
dist = null;
}
if (path == null) {
helper.fault(lang.translate("core.manage.file.path.required"));
return;
}
path = realPath(path);
if (path == null) {
helper.fault(lang.translate("core.manage.file.path.is.error"));
return;
}
file = new File(path);
if (!file.exists()) {
helper.fault(lang.translate("core.manage.file.path.is.not.exist"));
return;
}
if (isDenyFile(file)) {
helper.fault(lang.translate("core.manage.file.interdicted"));
return;
}
// 改名移动
if (dist != null) {
dist = realPath(dist);
if (dist == null) {
helper.fault(lang.translate("core.manage.file.path.is.error"));
return;
}
dizt = new File(dist);
if (dizt.exists()) {
helper.fault(lang.translate("core.manage.file.dist.is.exist"));
return;
}
if (isDenyFile(file)) {
helper.fault(lang.translate("core.manage.file.interdicted"));
return;
}
if (!file.renameTo(dizt)) {
helper.fault(lang.translate("core.manage.file.rename.failed"));
return;
}
file = dizt;
}
// 写入文件
try {
saveFile(file, text);
} catch (Exception ex) {
CoreLogger.error(ex);
helper.fault(lang.translate("core.manage.file.update.failed"));
return;
}
helper.reply("");
}
Aggregations