示例#1
0
func CheckAuthValid(sessionId, accessToken string, vResult *ApiResult) (userId int, valid bool) {
	if sessionId == "" {
		vResult.SetFormatCode(API_PARAM_ERROR, "session id is empty")
		return
	}

	if accessToken == "" {
		vResult.SetFormatCode(API_PARAM_ERROR, "access token is empty")
		return
	}

	if !utils.IsAccessTokenValid(sessionId, accessToken) {
		vResult.SetCode(API_UNAUTHORIZED_ERROR)
		return
	}

	gUserId, gErr := model.GetSession(sessionId)
	if gErr != nil {
		vResult.SetCode(API_SESSION_EXPIRED_ERROR)
		return
	}

	userId = gUserId
	valid = true
	return
}
func StartPublish(sessionId, accessToken, streamTitle, streamId, streamQualityStr, streamOrientationStr string, pResult *StartPublishResult) {
	if _, valid := CheckAuthValid(sessionId, accessToken, &pResult.ApiResult); !valid {
		return
	}

	if streamId == "" {
		pResult.SetFormatCode(API_PARAM_ERROR, "stream id is empty")
		return
	}

	if streamTitle == "" {
		pResult.SetFormatCode(API_PARAM_ERROR, "stream title is empty")
		return
	}

	streamQuality, pErr := strconv.ParseInt(streamQualityStr, 10, 64)
	if pErr != nil {
		pResult.SetFormatCode(API_PARAM_ERROR, "stream quality is invalid")
		return
	}

	streamOrientation, pErr := strconv.ParseInt(streamOrientationStr, 10, 64)
	if pErr != nil {
		pResult.SetFormatCode(API_PARAM_ERROR, "stream orientation is invalid")
		return
	}

	userId, gErr := model.GetSession(sessionId)
	if gErr != nil {
		pResult.SetCode(API_SERVER_ERROR)
		return
	}

	publishId, cErr := model.CreateNewPublish(userId, streamId, streamTitle, int(streamQuality), int(streamOrientation))
	if cErr != nil {
		pResult.SetCode(API_SERVER_ERROR)
		return
	}

	pResult.PublishId = publishId
	pResult.SetOk()

	return
}