xx 2 лет назад
Родитель
Сommit
4c9941b1c3
2 измененных файлов с 15 добавлено и 22 удалено
  1. 1 7
      src/core/interceptormanager.cpp
  2. 14 15
      www/api/lib/interceptor.lua

+ 1 - 7
src/core/interceptormanager.cpp

@@ -47,16 +47,10 @@ bool interceptor_manager::callback(network::http::reqpack* reqpack, const std::s
 		module::request m_request(reqpack->request());
 		module::response m_response(reqpack->response());
 
-		lbResult();
-
 		(*lua->state)["response"] = m_response;
 		(*lua->state)["request"] = m_request;
 
-		auto result = (*lua->state)["access"]();
-		if (!result.valid()) {
-			sol::error err = result;
-			throw ylib::exception(err.what());
-		}
+		auto result = lbResult();
 		ok_continue = result.get<bool>();
 	}
 	catch (const std::exception& e)

+ 14 - 15
www/api/lib/interceptor.lua

@@ -1,18 +1,17 @@
 require "website"
-function access()
-	if string.sub(request:filepath(),1,12) == "/api/public/" then
-		--公共开放接口
-		return true
-	elseif string.sub(request:filepath(),1,11) == "/api/admin/" then
-		--管理员目录,需要验证权限
-		print(param("key"),"\t")
-		if param("key") == nil or param("key") ~= "123456" then
-			response:send("key不正确")
-			return false
-		end
-		return true
-	else
-		response:send("仅允许访问 /api/public 和 /api/admin 目录")
+
+if string.sub(request:filepath(),1,12) == "/api/public/" then
+	--公共开放接口
+	return true
+elseif string.sub(request:filepath(),1,11) == "/api/admin/" then
+	--管理员目录,需要验证权限
+	print(param("key"),"\t")
+	if param("key") == nil or param("key") ~= "123456" then
+		response:send("key不正确")
 		return false
 	end
-end
+	return true
+else
+	response:send("仅允许访问 /api/public 和 /api/admin 目录")
+	return false
+end